Commit c783b1fc by Dave Gynn

Address spec deprecation warnings and failures

* update aruba methods for in_current_dir and check_file_presence
* switch rspec syntax from should to expect
* configure raise_in_transactional_callbacks if AR >= 4.2
* remove paperclip itself from Appraisal
This also updates Travis to use the default bundler (to enable caching) and to build primary rubies first
parent 947fbf6e
rvm:
- 2.0
- 2.1
- 2.2.2
- jruby-19mode
- rbx-2
- 2.0.0
- 2.1.1
- 2.2.2
install:
- "travis_retry bundle install"
script: "bundle exec rake clean spec cucumber"
......
appraise "3.2" do
gem "rails", "~> 3.2.0"
gem "paperclip", :path => "../"
end
appraise "4.1" do
gem "rails", "~> 4.1.0"
gem "paperclip", :path => "../"
end
appraise "4.2" do
gem "rails", "~> 4.2.0"
gem "paperclip", :path => "../"
end
......@@ -10,7 +10,7 @@ end
World(AttachmentHelpers)
When /^I modify my attachment definition to:$/ do |definition|
content = in_current_dir { File.read("app/models/user.rb") }
content = cd(".") { File.read("app/models/user.rb") }
name = content[/has_attached_file :\w+/][/:\w+/]
content.gsub!(/has_attached_file.+end/m, <<-FILE)
#{definition}
......@@ -19,7 +19,7 @@ When /^I modify my attachment definition to:$/ do |definition|
FILE
write_file "app/models/user.rb", content
in_current_dir { FileUtils.rm_rf ".rbx" }
cd(".") { FileUtils.rm_rf ".rbx" }
end
When /^I upload the fixture "([^"]*)"$/ do |filename|
......@@ -27,20 +27,20 @@ When /^I upload the fixture "([^"]*)"$/ do |filename|
end
Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension|
in_current_dir do
cd(".") do
geometry = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
geometry.should == dimension
expect(geometry).to eq(dimension)
end
end
Then /^the attachment "([^"]*)" should exist$/ do |filename|
in_current_dir do
File.exist?(attachment_path(filename)).should be
cd(".") do
expect(File.exist?(attachment_path(filename))).to be true
end
end
When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
in_current_dir do
cd(".") do
require 'fileutils'
FileUtils.rm_f attachment_path(attachment_filename)
FileUtils.cp fixture_path(fixture_filename), attachment_path(attachment_filename)
......@@ -48,7 +48,7 @@ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachme
end
Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
cd(".") do
begin
# Use mime/types/columnar if available, for reduced memory usage
require "mime/types/columnar"
......@@ -57,32 +57,33 @@ Then /^the attachment should have the same content type as the fixture "([^"]*)"
end
attachment_content_type = `bundle exec #{runner_command} "puts User.last.attachment_content_type"`.strip
attachment_content_type.should == MIME::Types.type_for(filename).first.content_type
expected = MIME::Types.type_for(filename).first.content_type
expect(attachment_content_type).to eq(expected)
end
end
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
cd(".") do
attachment_file_name = `bundle exec #{runner_command} "puts User.last.attachment_file_name"`.strip
attachment_file_name.should == File.name(fixture_path(filename)).to_s
expect(attachment_file_name).to eq(File.name(fixture_path(filename)).to_s)
end
end
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename|
in_current_dir do
cd(".") do
attachment_file_size = `bundle exec #{runner_command} "puts User.last.attachment_file_size"`.strip
attachment_file_size.should == File.size(fixture_path(filename)).to_s
expect(attachment_file_size).to eq(File.size(fixture_path(filename)).to_s)
end
end
Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
in_current_dir do
check_file_presence([attachment_path(filename)], !not_exist)
cd(".") do
expect(attachment_path(filename)).not_to be_an_existing_file
end
end
Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
in_current_dir do
cd(".") do
columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
expect_columns = [
["#{attachment_name}_file_name", :string],
......@@ -90,13 +91,12 @@ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
["#{attachment_name}_file_size", :integer],
["#{attachment_name}_updated_at", :datetime]
]
expect_columns.all?{ |column| columns.include? column }.should eq true
expect(columns).to include(*expect_columns)
end
end
Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
in_current_dir do
cd(".") do
columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
expect_columns = [
["#{attachment_name}_file_name", :string],
......@@ -105,6 +105,6 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
["#{attachment_name}_updated_at", :datetime]
]
expect_columns.none?{ |column| columns.include? column }.should eq true
expect(columns).not_to include(*expect_columns)
end
end
Then %r{I should see an image with a path of "([^"]*)"} do |path|
page.should have_css("img[src^='#{path}']")
expect(page).to have_css("img[src^='#{path}']")
end
Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
......@@ -11,5 +11,5 @@ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
page.body
end
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected
expect(actual).to eq(expected)
end
......@@ -24,7 +24,7 @@ Given /^I generate a new rails application$/ do
end
Given "I fix the application.rb for 3.0.12" do
in_current_dir do
cd(".") do
File.open("config/application.rb", "a") do |f|
f << "ActionController::Base.config.relative_url_root = ''"
end
......@@ -32,7 +32,7 @@ Given "I fix the application.rb for 3.0.12" do
end
Given "I allow the attachment to be submitted" do
in_current_dir do
cd(".") do
transform_file("app/controllers/users_controller.rb") do |content|
content.gsub("params.require(:user).permit(:name)",
"params.require(:user).permit!")
......@@ -41,7 +41,7 @@ Given "I allow the attachment to be submitted" do
end
Given "I remove turbolinks" do
in_current_dir do
cd(".") do
transform_file("app/assets/javascripts/application.js") do |content|
content.gsub("//= require turbolinks", "")
end
......@@ -70,7 +70,7 @@ def attach_attachment(name, definition = nil)
snippet += definition
end
snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
in_current_dir do
cd(".") do
transform_file("app/models/user.rb") do |content|
content.sub(/end\Z/, "#{snippet}\nend")
end
......@@ -78,7 +78,7 @@ def attach_attachment(name, definition = nil)
end
Given "I empty the application.js file" do
in_current_dir do
cd(".") do
transform_file("app/assets/javascripts/application.js") do |content|
""
end
......@@ -128,7 +128,7 @@ end
Given /^I add this snippet to the User model:$/ do |snippet|
file_name = "app/models/user.rb"
in_current_dir do
cd(".") do
content = File.read(file_name)
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
end
......@@ -136,14 +136,14 @@ end
Given /^I add this snippet to config\/application.rb:$/ do |snippet|
file_name = "config/application.rb"
in_current_dir do
cd(".") do
content = File.read(file_name)
File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
end
end
Given /^I start the rails application$/ do
in_current_dir do
cd(".") do
require "./config/environment"
require "capybara/rails"
end
......@@ -154,7 +154,7 @@ Given /^I reload my application$/ do
end
When /^I turn off class caching$/ do
in_current_dir do
cd(".") do
file = "config/environments/test.rb"
config = IO.read(file)
config.gsub!(%r{^\s*config.cache_classes.*$},
......@@ -166,7 +166,7 @@ end
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
expected = IO.read(path)
actual = read_from_web(web_file)
actual.should == expected
expect(actual).to eq(expected)
end
When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
......@@ -198,7 +198,7 @@ end
Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
filename = "#{directory}/#{processor}.rb"
in_current_dir do
cd(".") do
FileUtils.mkdir_p directory
File.open(filename, "w") do |f|
f.write(<<-CLASS)
......
......@@ -103,107 +103,5 @@ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
end
Then /^(?:|I )should see "([^"]*)"$/ do |text|
if page.respond_to? :should
page.should have_content(text)
else
assert page.has_content?(text)
end
end
Then /^(?:|I )should see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)
if page.respond_to? :should
page.should have_xpath('//*', :text => regexp)
else
assert page.has_xpath?('//*', :text => regexp)
end
end
Then /^(?:|I )should not see "([^"]*)"$/ do |text|
if page.respond_to? :should
page.should have_no_content(text)
else
assert page.has_no_content?(text)
end
end
Then /^(?:|I )should not see \/([^\/]*)\/$/ do |regexp|
regexp = Regexp.new(regexp)
if page.respond_to? :should
page.should have_no_xpath('//*', :text => regexp)
else
assert page.has_no_xpath?('//*', :text => regexp)
end
end
Then /^the "([^"]*)" field(?: within (.*))? should contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
if field.value.respond_to? :should
field.value.should =~ /#{value}/
else
assert_match(/#{value}/, field.value)
end
end
end
Then /^the "([^"]*)" field(?: within (.*))? should not contain "([^"]*)"$/ do |field, parent, value|
with_scope(parent) do
field = find_field(field)
if field.value.respond_to? :should_not
field.value.should_not =~ /#{value}/
else
assert_no_match(/#{value}/, field.value)
end
end
end
Then /^the "([^"]*)" checkbox(?: within (.*))? should be checked$/ do |label, parent|
with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should eq true
else
assert field_checked
end
end
end
Then /^the "([^"]*)" checkbox(?: within (.*))? should not be checked$/ do |label, parent|
with_scope(parent) do
field_checked = find_field(label)['checked']
if field_checked.respond_to? :should
field_checked.should eq false
else
assert !field_checked
end
end
end
Then /^(?:|I )should be on (.+)$/ do |page_name|
current_path = URI.parse(current_url).path
if current_path.respond_to? :should
current_path.should == path_to(page_name)
else
assert_equal path_to(page_name), current_path
end
end
Then /^(?:|I )should have the following query string:$/ do |expected_pairs|
query = URI.parse(current_url).query
actual_params = query ? CGI.parse(query) : {}
expected_params = {}
expected_pairs.rows_hash.each_pair{|k,v| expected_params[k] = v.split(',')}
if actual_params.respond_to? :should
actual_params.should == expected_params
else
assert_equal expected_params, actual_params
end
end
Then /^show me the page$/ do
save_and_open_page
expect(page).to have_content(text)
end
module FileHelpers
def append_to(path, contents)
in_current_dir do
cd(".") do
File.open(path, "a") do |file|
file.puts
file.puts contents
......@@ -13,7 +13,7 @@ module FileHelpers
end
def comment_out_gem_in_gemfile(gemname)
in_current_dir do
cd(".") do
gemfile = File.read("Gemfile")
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
......
......@@ -8,8 +8,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 3.2.15"
gem "paperclip", :path => "../"
gem "rails", "~> 3.2.0"
group :development, :test do
gem "mime-types", "~> 1.16"
......
......@@ -9,7 +9,6 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 4.1.0"
gem "paperclip", :path => "../"
group :development, :test do
gem "mime-types", "~> 1.16"
......
......@@ -9,7 +9,6 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx
gem "pry"
gem "rails", "~> 4.2.0"
gem "paperclip", :path => "../"
group :development, :test do
gem "mime-types", "~> 1.16"
......
......@@ -20,6 +20,9 @@ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config['test'])
unless ActiveRecord::VERSION::STRING < "4.2"
ActiveRecord::Base.raise_in_transactional_callbacks = true
end
Paperclip.options[:logger] = ActiveRecord::Base.logger
Dir[File.join(ROOT, 'spec', 'support', '**', '*.rb')].each{|f| require f }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment