diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b0473130..daeb88792 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,9 @@ jobs: RAILS_VERSION: 'main' # Rails 8.0 builds >= 3.2 + - ruby: 3.4.0-rc1 + env: + RAILS_VERSION: '~> 8.0.0' - ruby: 3.3 env: RAILS_VERSION: '~> 8.0.0' diff --git a/Gemfile b/Gemfile index 5df5cc6e4..609895b36 100644 --- a/Gemfile +++ b/Gemfile @@ -16,6 +16,10 @@ gem 'ffi', '> 1.15.5' gem 'rake', '> 12' gem 'rubocop', '~> 1.28.2' +if RUBY_VERSION.to_f > 3.3 + gem 'cucumber', git: 'https://github.com/cucumber/cucumber-ruby', branch: 'main' +end + custom_gemfile = File.expand_path('Gemfile-custom', __dir__) eval_gemfile custom_gemfile if File.exist?(custom_gemfile) diff --git a/lib/rspec/rails/matchers/have_enqueued_mail.rb b/lib/rspec/rails/matchers/have_enqueued_mail.rb index cf4576e57..14f8f0111 100644 --- a/lib/rspec/rails/matchers/have_enqueued_mail.rb +++ b/lib/rspec/rails/matchers/have_enqueued_mail.rb @@ -129,13 +129,13 @@ def unmatching_mail_jobs end def unmatching_mail_jobs_message - msg = "Queued deliveries:" + messages = ["Queued deliveries:"] unmatching_mail_jobs.each do |job| - msg << "\n #{mail_job_message(job)}" + messages << " #{mail_job_message(job)}" end - msg + messages.join("\n") end def mail_job_message(job) diff --git a/rspec-rails.gemspec b/rspec-rails.gemspec index 788977e11..dd8e24ea6 100644 --- a/rspec-rails.gemspec +++ b/rspec-rails.gemspec @@ -55,5 +55,5 @@ Gem::Specification.new do |s| s.add_development_dependency 'ammeter', '~> 1.1.5' s.add_development_dependency 'aruba', '~> 0.14.12' - s.add_development_dependency 'cucumber', '~> 7.0' + s.add_development_dependency 'cucumber', '> 7.0' end diff --git a/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb b/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb index 67d4a51c7..fb37fec13 100644 --- a/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb +++ b/spec/rspec/rails/matchers/action_cable/have_broadcasted_to_spec.rb @@ -248,12 +248,16 @@ def broadcast(stream, msg) end it "has an appropriate description including the matcher's description when qualified with `#with` and a composable matcher" do - expect( - have_broadcasted_to("my_stream") + description = have_broadcasted_to("my_stream") .from_channel(channel) .with(a_hash_including(a: :b)) .description - ).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {:a => :b}") + + if RUBY_VERSION >= '3.4' + expect(description).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {a: :b}") + else + expect(description).to eq("have broadcasted exactly 1 messages to my_stream with a hash including {:a => :b}") + end end end end diff --git a/spec/rspec/rails/matchers/be_a_new_spec.rb b/spec/rspec/rails/matchers/be_a_new_spec.rb index 76906a56f..d24e3c699 100644 --- a/spec/rspec/rails/matchers/be_a_new_spec.rb +++ b/spec/rspec/rails/matchers/be_a_new_spec.rb @@ -71,10 +71,16 @@ def new_record?; true; end end it "fails" do + message = + if RUBY_VERSION >= '3.4' + "attribute {\"foo\" => (a string matching \"bar\")} was not set on #{record.inspect}" + else + "attribute {\"foo\"=>(a string matching \"bar\")} was not set on #{record.inspect}" + end expect { expect(record).to be_a_new(record.class).with( foo: a_string_matching("bar")) - }.to raise_error("attribute {\"foo\"=>(a string matching \"bar\")} was not set on #{record.inspect}") + }.to raise_error(message) end context "matcher is wrong type" do @@ -101,12 +107,18 @@ def new_record?; true; end context "only one matcher present in actual" do it "fails" do + message = + if RUBY_VERSION >= '3.4' + "attribute {\"bar\" => (a string matching \"barn\")} was not set on #{record.inspect}" + else + "attribute {\"bar\"=>(a string matching \"barn\")} was not set on #{record.inspect}" + end expect { expect(record).to be_a_new(record.class).with( foo: a_string_matching("foo"), bar: a_string_matching("barn") ) - }.to raise_error("attribute {\"bar\"=>(a string matching \"barn\")} was not set on #{record.inspect}") + }.to raise_error(message) end end end @@ -118,19 +130,29 @@ def new_record?; true; end expect(record).to be_a_new(record.class).with(zoo: 'zoo', car: 'car') }.to raise_error { |e| expect(e.message).to match(/attributes \{.*\} were not set on #{Regexp.escape record.inspect}/) - expect(e.message).to match(/"zoo"=>"zoo"/) - expect(e.message).to match(/"car"=>"car"/) + if RUBY_VERSION >= '3.4' + expect(e.message).to match(/"zoo" => "zoo"/) + expect(e.message).to match(/"car" => "car"/) + else + expect(e.message).to match(/"zoo"=>"zoo"/) + expect(e.message).to match(/"car"=>"car"/) + end } end end context "one attribute value not the same" do it "fails" do + message = + if RUBY_VERSION >= '3.4' + %(attribute {"foo" => "bar"} was not set on #{record.inspect}) + else + %(attribute {"foo"=>"bar"} was not set on #{record.inspect}) + end + expect { expect(record).to be_a_new(record.class).with(foo: 'bar') - }.to raise_error( - %(attribute {"foo"=>"bar"} was not set on #{record.inspect}) - ) + }.to raise_error(message) end end end @@ -166,20 +188,30 @@ def new_record?; false; end expect(record).to be_a_new(String).with(zoo: 'zoo', car: 'car') }.to raise_error { |e| expect(e.message).to match(/expected #{Regexp.escape record.inspect} to be a new String and attributes \{.*\} were not set on #{Regexp.escape record.inspect}/) - expect(e.message).to match(/"zoo"=>"zoo"/) - expect(e.message).to match(/"car"=>"car"/) + if RUBY_VERSION >= '3.4' + expect(e.message).to match(/"zoo" => "zoo"/) + expect(e.message).to match(/"car" => "car"/) + else + expect(e.message).to match(/"zoo"=>"zoo"/) + expect(e.message).to match(/"car"=>"car"/) + end } end end context "one attribute value not the same" do it "fails" do + message = + "expected #{record.inspect} to be a new String and " + + if RUBY_VERSION >= '3.4' + %(attribute {"foo" => "bar"} was not set on #{record.inspect}) + else + %(attribute {"foo"=>"bar"} was not set on #{record.inspect}) + end + expect { expect(record).to be_a_new(String).with(foo: 'bar') - }.to raise_error( - "expected #{record.inspect} to be a new String and " + - %(attribute {"foo"=>"bar"} was not set on #{record.inspect}) - ) + }.to raise_error(message) end end end diff --git a/spec/rspec/rails/matchers/be_routable_spec.rb b/spec/rspec/rails/matchers/be_routable_spec.rb index c3a6a1b15..65edb2bb5 100644 --- a/spec/rspec/rails/matchers/be_routable_spec.rb +++ b/spec/rspec/rails/matchers/be_routable_spec.rb @@ -18,9 +18,17 @@ it "fails if routes do not recognize the path" do allow(routes).to receive(:recognize_path) { raise ActionController::RoutingError, 'ignore' } + + message = + if RUBY_VERSION >= '3.4' + /expected \{get: "\/a\/path"\} to be routable/ + else + /expected \{:get=>"\/a\/path"\} to be routable/ + end + expect do expect({ get: "/a/path" }).to be_routable - end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/) + end.to raise_error(message) end end @@ -35,9 +43,17 @@ it "fails if routes recognize the path" do allow(routes).to receive(:recognize_path) { { controller: "foo" } } + + message = + if RUBY_VERSION >= '3.4' + /expected \{get: "\/a\/path"\} not to be routable, but it routes to \{controller: "foo"\}/ + else + /expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/ + end + expect do expect({ get: "/a/path" }).not_to be_routable - end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/) + end.to raise_error(message) end end end diff --git a/spec/rspec/rails/matchers/route_to_spec.rb b/spec/rspec/rails/matchers/route_to_spec.rb index ae49791f8..8b1d7836b 100644 --- a/spec/rspec/rails/matchers/route_to_spec.rb +++ b/spec/rspec/rails/matchers/route_to_spec.rb @@ -9,7 +9,15 @@ def assert_recognizes(*) it "provides a description" do matcher = route_to("these" => "options") matcher.matches?(get: "path") - expect(matcher.description).to eq("route {:get=>\"path\"} to {\"these\"=>\"options\"}") + + description = + if RUBY_VERSION >= '3.4' + "route {get: \"path\"} to {\"these\" => \"options\"}" + else + "route {:get=>\"path\"} to {\"these\"=>\"options\"}" + end + + expect(matcher.description).to eq(description) end it "delegates to assert_recognizes" do @@ -107,9 +115,16 @@ def assert_recognizes(*) context "with should_not" do context "when assert_recognizes passes" do it "fails with custom message" do + message = + if RUBY_VERSION >= '3.4' + /expected \{get: "path"\} not to route to \{"these" => "options"\}/ + else + /expected \{:get=>"path"\} not to route to \{"these"=>"options"\}/ + end + expect { expect({ get: "path" }).not_to route_to("these" => "options") - }.to raise_error(/expected \{:get=>"path"\} not to route to \{"these"=>"options"\}/) + }.to raise_error(message) end end diff --git a/spec/sanity_check_spec.rb b/spec/sanity_check_spec.rb index 4746a157e..7faef98a8 100644 --- a/spec/sanity_check_spec.rb +++ b/spec/sanity_check_spec.rb @@ -29,6 +29,7 @@ def with_clean_env .to match(/uninitialized constant RSpec::Support/) .or match(/undefined method `require_rspec_core' for RSpec::Support:Module/) .or match(/undefined method `require_rspec_core' for module RSpec::Support/) + .or match(/undefined method 'require_rspec_core' for module RSpec::Support/) expect($?.exitstatus).to eq(1) end