Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Enable CI for Ruby head #2821

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
58 changes: 45 additions & 13 deletions spec/rspec/rails/matchers/be_a_new_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 18 additions & 2 deletions spec/rspec/rails/matchers/be_routable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
19 changes: 17 additions & 2 deletions spec/rspec/rails/matchers/route_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
Loading