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: rvm:
- 2.0
- 2.1
- 2.2.2
- jruby-19mode - jruby-19mode
- rbx-2 - rbx-2
- 2.0.0
- 2.1.1
- 2.2.2
install:
- "travis_retry bundle install"
script: "bundle exec rake clean spec cucumber" script: "bundle exec rake clean spec cucumber"
......
appraise "3.2" do appraise "3.2" do
gem "rails", "~> 3.2.0" gem "rails", "~> 3.2.0"
gem "paperclip", :path => "../"
end end
appraise "4.1" do appraise "4.1" do
gem "rails", "~> 4.1.0" gem "rails", "~> 4.1.0"
gem "paperclip", :path => "../"
end end
appraise "4.2" do appraise "4.2" do
gem "rails", "~> 4.2.0" gem "rails", "~> 4.2.0"
gem "paperclip", :path => "../"
end end
...@@ -10,7 +10,7 @@ end ...@@ -10,7 +10,7 @@ end
World(AttachmentHelpers) World(AttachmentHelpers)
When /^I modify my attachment definition to:$/ do |definition| 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+/] name = content[/has_attached_file :\w+/][/:\w+/]
content.gsub!(/has_attached_file.+end/m, <<-FILE) content.gsub!(/has_attached_file.+end/m, <<-FILE)
#{definition} #{definition}
...@@ -19,7 +19,7 @@ When /^I modify my attachment definition to:$/ do |definition| ...@@ -19,7 +19,7 @@ When /^I modify my attachment definition to:$/ do |definition|
FILE FILE
write_file "app/models/user.rb", content write_file "app/models/user.rb", content
in_current_dir { FileUtils.rm_rf ".rbx" } cd(".") { FileUtils.rm_rf ".rbx" }
end end
When /^I upload the fixture "([^"]*)"$/ do |filename| When /^I upload the fixture "([^"]*)"$/ do |filename|
...@@ -27,20 +27,20 @@ When /^I upload the fixture "([^"]*)"$/ do |filename| ...@@ -27,20 +27,20 @@ When /^I upload the fixture "([^"]*)"$/ do |filename|
end end
Then /^the attachment "([^"]*)" should have a dimension of (\d+x\d+)$/ do |filename, dimension| 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 = `identify -format "%wx%h" "#{attachment_path(filename)}"`.strip
geometry.should == dimension expect(geometry).to eq(dimension)
end end
end end
Then /^the attachment "([^"]*)" should exist$/ do |filename| Then /^the attachment "([^"]*)" should exist$/ do |filename|
in_current_dir do cd(".") do
File.exist?(attachment_path(filename)).should be expect(File.exist?(attachment_path(filename))).to be true
end end
end end
When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename| When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachment_filename, fixture_filename|
in_current_dir do cd(".") do
require 'fileutils' require 'fileutils'
FileUtils.rm_f attachment_path(attachment_filename) FileUtils.rm_f attachment_path(attachment_filename)
FileUtils.cp fixture_path(fixture_filename), 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 ...@@ -48,7 +48,7 @@ When /^I swap the attachment "([^"]*)" with the fixture "([^"]*)"$/ do |attachme
end end
Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename| Then /^the attachment should have the same content type as the fixture "([^"]*)"$/ do |filename|
in_current_dir do cd(".") do
begin begin
# Use mime/types/columnar if available, for reduced memory usage # Use mime/types/columnar if available, for reduced memory usage
require "mime/types/columnar" require "mime/types/columnar"
...@@ -57,32 +57,33 @@ Then /^the attachment should have the same content type as the fixture "([^"]*)" ...@@ -57,32 +57,33 @@ Then /^the attachment should have the same content type as the fixture "([^"]*)"
end end
attachment_content_type = `bundle exec #{runner_command} "puts User.last.attachment_content_type"`.strip 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
end end
Then /^the attachment should have the same file name as the fixture "([^"]*)"$/ do |filename| 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 = `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
end end
Then /^the attachment should have the same file size as the fixture "([^"]*)"$/ do |filename| 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 = `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
end end
Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist| Then /^the attachment file "([^"]*)" should (not )?exist$/ do |filename, not_exist|
in_current_dir do cd(".") do
check_file_presence([attachment_path(filename)], !not_exist) expect(attachment_path(filename)).not_to be_an_existing_file
end end
end end
Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name| 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) columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
expect_columns = [ expect_columns = [
["#{attachment_name}_file_name", :string], ["#{attachment_name}_file_name", :string],
...@@ -90,13 +91,12 @@ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name| ...@@ -90,13 +91,12 @@ Then /^I should have attachment columns for "([^"]*)"$/ do |attachment_name|
["#{attachment_name}_file_size", :integer], ["#{attachment_name}_file_size", :integer],
["#{attachment_name}_updated_at", :datetime] ["#{attachment_name}_updated_at", :datetime]
] ]
expect(columns).to include(*expect_columns)
expect_columns.all?{ |column| columns.include? column }.should eq true
end end
end end
Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name| 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) columns = eval(`bundle exec #{runner_command} "puts User.columns.map{ |column| [column.name, column.type] }.inspect"`.strip)
expect_columns = [ expect_columns = [
["#{attachment_name}_file_name", :string], ["#{attachment_name}_file_name", :string],
...@@ -105,6 +105,6 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name| ...@@ -105,6 +105,6 @@ Then /^I should not have attachment columns for "([^"]*)"$/ do |attachment_name|
["#{attachment_name}_updated_at", :datetime] ["#{attachment_name}_updated_at", :datetime]
] ]
expect_columns.none?{ |column| columns.include? column }.should eq true expect(columns).not_to include(*expect_columns)
end end
end end
Then %r{I should see an image with a path of "([^"]*)"} do |path| 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 end
Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path| 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| ...@@ -11,5 +11,5 @@ Then %r{^the file at "([^"]*)" is the same as "([^"]*)"$} do |web_file, path|
page.body page.body
end end
actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding) actual.force_encoding("UTF-8") if actual.respond_to?(:force_encoding)
actual.should == expected expect(actual).to eq(expected)
end end
...@@ -24,7 +24,7 @@ Given /^I generate a new rails application$/ do ...@@ -24,7 +24,7 @@ Given /^I generate a new rails application$/ do
end end
Given "I fix the application.rb for 3.0.12" do 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| File.open("config/application.rb", "a") do |f|
f << "ActionController::Base.config.relative_url_root = ''" f << "ActionController::Base.config.relative_url_root = ''"
end end
...@@ -32,7 +32,7 @@ Given "I fix the application.rb for 3.0.12" do ...@@ -32,7 +32,7 @@ Given "I fix the application.rb for 3.0.12" do
end end
Given "I allow the attachment to be submitted" do Given "I allow the attachment to be submitted" do
in_current_dir do cd(".") do
transform_file("app/controllers/users_controller.rb") do |content| transform_file("app/controllers/users_controller.rb") do |content|
content.gsub("params.require(:user).permit(:name)", content.gsub("params.require(:user).permit(:name)",
"params.require(:user).permit!") "params.require(:user).permit!")
...@@ -41,7 +41,7 @@ Given "I allow the attachment to be submitted" do ...@@ -41,7 +41,7 @@ Given "I allow the attachment to be submitted" do
end end
Given "I remove turbolinks" do Given "I remove turbolinks" do
in_current_dir do cd(".") do
transform_file("app/assets/javascripts/application.js") do |content| transform_file("app/assets/javascripts/application.js") do |content|
content.gsub("//= require turbolinks", "") content.gsub("//= require turbolinks", "")
end end
...@@ -70,7 +70,7 @@ def attach_attachment(name, definition = nil) ...@@ -70,7 +70,7 @@ def attach_attachment(name, definition = nil)
snippet += definition snippet += definition
end end
snippet += "\ndo_not_validate_attachment_file_type :#{name}\n" snippet += "\ndo_not_validate_attachment_file_type :#{name}\n"
in_current_dir do cd(".") do
transform_file("app/models/user.rb") do |content| transform_file("app/models/user.rb") do |content|
content.sub(/end\Z/, "#{snippet}\nend") content.sub(/end\Z/, "#{snippet}\nend")
end end
...@@ -78,7 +78,7 @@ def attach_attachment(name, definition = nil) ...@@ -78,7 +78,7 @@ def attach_attachment(name, definition = nil)
end end
Given "I empty the application.js file" do Given "I empty the application.js file" do
in_current_dir do cd(".") do
transform_file("app/assets/javascripts/application.js") do |content| transform_file("app/assets/javascripts/application.js") do |content|
"" ""
end end
...@@ -128,7 +128,7 @@ end ...@@ -128,7 +128,7 @@ end
Given /^I add this snippet to the User model:$/ do |snippet| Given /^I add this snippet to the User model:$/ do |snippet|
file_name = "app/models/user.rb" file_name = "app/models/user.rb"
in_current_dir do cd(".") do
content = File.read(file_name) content = File.read(file_name)
File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") } File.open(file_name, 'w') { |f| f << content.sub(/end\Z/, "#{snippet}\nend") }
end end
...@@ -136,14 +136,14 @@ end ...@@ -136,14 +136,14 @@ end
Given /^I add this snippet to config\/application.rb:$/ do |snippet| Given /^I add this snippet to config\/application.rb:$/ do |snippet|
file_name = "config/application.rb" file_name = "config/application.rb"
in_current_dir do cd(".") do
content = File.read(file_name) 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")} File.open(file_name, 'w') {|f| f << content.sub(/class Application < Rails::Application.*$/, "class Application < Rails::Application\n#{snippet}\n")}
end end
end end
Given /^I start the rails application$/ do Given /^I start the rails application$/ do
in_current_dir do cd(".") do
require "./config/environment" require "./config/environment"
require "capybara/rails" require "capybara/rails"
end end
...@@ -154,7 +154,7 @@ Given /^I reload my application$/ do ...@@ -154,7 +154,7 @@ Given /^I reload my application$/ do
end end
When /^I turn off class caching$/ do When /^I turn off class caching$/ do
in_current_dir do cd(".") do
file = "config/environments/test.rb" file = "config/environments/test.rb"
config = IO.read(file) config = IO.read(file)
config.gsub!(%r{^\s*config.cache_classes.*$}, config.gsub!(%r{^\s*config.cache_classes.*$},
...@@ -166,7 +166,7 @@ end ...@@ -166,7 +166,7 @@ end
Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path| Then /^the file at "([^"]*)" should be the same as "([^"]*)"$/ do |web_file, path|
expected = IO.read(path) expected = IO.read(path)
actual = read_from_web(web_file) actual = read_from_web(web_file)
actual.should == expected expect(actual).to eq(expected)
end end
When /^I configure the application to use "([^\"]+)" from this project$/ do |name| When /^I configure the application to use "([^\"]+)" from this project$/ do |name|
...@@ -198,7 +198,7 @@ end ...@@ -198,7 +198,7 @@ end
Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory| Given(/^I add a "(.*?)" processor in "(.*?)"$/) do |processor, directory|
filename = "#{directory}/#{processor}.rb" filename = "#{directory}/#{processor}.rb"
in_current_dir do cd(".") do
FileUtils.mkdir_p directory FileUtils.mkdir_p directory
File.open(filename, "w") do |f| File.open(filename, "w") do |f|
f.write(<<-CLASS) f.write(<<-CLASS)
......
...@@ -103,107 +103,5 @@ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field| ...@@ -103,107 +103,5 @@ When /^(?:|I )attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
end end
Then /^(?:|I )should see "([^"]*)"$/ do |text| Then /^(?:|I )should see "([^"]*)"$/ do |text|
if page.respond_to? :should expect(page).to have_content(text)
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
end end
module FileHelpers module FileHelpers
def append_to(path, contents) def append_to(path, contents)
in_current_dir do cd(".") do
File.open(path, "a") do |file| File.open(path, "a") do |file|
file.puts file.puts
file.puts contents file.puts contents
...@@ -13,7 +13,7 @@ module FileHelpers ...@@ -13,7 +13,7 @@ module FileHelpers
end end
def comment_out_gem_in_gemfile(gemname) def comment_out_gem_in_gemfile(gemname)
in_current_dir do cd(".") do
gemfile = File.read("Gemfile") gemfile = File.read("Gemfile")
gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2") gemfile.sub!(/^(\s*)(gem\s*['"]#{gemname})/, "\\1# \\2")
File.open("Gemfile", 'w'){ |file| file.write(gemfile) } File.open("Gemfile", 'w'){ |file| file.write(gemfile) }
......
...@@ -8,8 +8,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby ...@@ -8,8 +8,7 @@ gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
gem "rubysl", :platforms => :rbx gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx gem "racc", :platforms => :rbx
gem "pry" gem "pry"
gem "rails", "~> 3.2.15" gem "rails", "~> 3.2.0"
gem "paperclip", :path => "../"
group :development, :test do group :development, :test do
gem "mime-types", "~> 1.16" gem "mime-types", "~> 1.16"
......
...@@ -9,7 +9,6 @@ gem "rubysl", :platforms => :rbx ...@@ -9,7 +9,6 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx gem "racc", :platforms => :rbx
gem "pry" gem "pry"
gem "rails", "~> 4.1.0" gem "rails", "~> 4.1.0"
gem "paperclip", :path => "../"
group :development, :test do group :development, :test do
gem "mime-types", "~> 1.16" gem "mime-types", "~> 1.16"
......
...@@ -9,7 +9,6 @@ gem "rubysl", :platforms => :rbx ...@@ -9,7 +9,6 @@ gem "rubysl", :platforms => :rbx
gem "racc", :platforms => :rbx gem "racc", :platforms => :rbx
gem "pry" gem "pry"
gem "rails", "~> 4.2.0" gem "rails", "~> 4.2.0"
gem "paperclip", :path => "../"
group :development, :test do group :development, :test do
gem "mime-types", "~> 1.16" gem "mime-types", "~> 1.16"
......
...@@ -20,6 +20,9 @@ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") ...@@ -20,6 +20,9 @@ FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures")
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml')) config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log") ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
ActiveRecord::Base.establish_connection(config['test']) 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 Paperclip.options[:logger] = ActiveRecord::Base.logger
Dir[File.join(ROOT, 'spec', 'support', '**', '*.rb')].each{|f| require f } 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