Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

raise_error behavior change under Ruby 2 #232

Closed
jjb opened this issue Apr 6, 2013 · 10 comments
Closed

raise_error behavior change under Ruby 2 #232

jjb opened this issue Apr 6, 2013 · 10 comments
Assignees
Milestone

Comments

@jjb
Copy link

jjb commented Apr 6, 2013

I'm seeing a behavior change when running under Ruby 2.0.

I have specs that looks like this. To make them pass under Ruby 2, I had to make the change noted in the comment near the end.

it "reraises the exception" do
  error = ActiveRecord::RecordInvalid.new(record)
  foos.should_receive(:create!).
    and_raise(error)
  expect{
    bar.create_foo(baz_id: baz_id)
  }.to raise_error(error) # this works as expected in 1.9.3
  # }.to raise_error(ActiveRecord::RecordInvalid) # i had to switch to this for 2.0.0
end

Is this expected? Is this because of a fundamental change in Ruby 2, or a bug in how rspec interacts with it?

Let me know if you want more info.

rails is 3.2.13

@myronmarston
Copy link
Member

It's not expected or previously known. Can you come up with an isolated example that demonstrates this?

@jjb
Copy link
Author

jjb commented Apr 7, 2013

@myronmarston ta-da! https://github.com/jjb/rspec-expectations-issue-232

see spec/models/foo_spec.rb

@jjb
Copy link
Author

jjb commented Apr 7, 2013

and here's the output of running specs under each version

➔ rbenv shell 1.9.3-p385-perf 
➔ rspec --format=documentation

Foo
  this spec works in both 1.9.3 and 2.0.0
  this spec works in 1.9.3 only

Finished in 0.00761 seconds
2 examples, 0 failures

Randomized with seed 23056

➔ rbenv shell 2.0.0-p0 
➔ rspec --format=documentation

Foo
  this spec works in both 1.9.3 and 2.0.0
  this spec works in 1.9.3 only (FAILED - 1)

Failures:

  1) Foo this spec works in 1.9.3 only
     Failure/Error: expect{subject.bar}.to raise_error(error)
       expected StandardError but nothing was raised
     # ./spec/models/foo_spec.rb:15:in `block (2 levels) in <top (required)>'

Finished in 0.01049 seconds
2 examples, 1 failure

Failed examples:

rspec ./spec/models/foo_spec.rb:14 # Foo this spec works in 1.9.3 only

Randomized with seed 2069

@fables-tales
Copy link
Member

I'm going to try and isolate/fix this today

@ghost ghost assigned fables-tales Apr 10, 2013
@fables-tales
Copy link
Member

I've isolated this to line 23 of this file

@jjb
Copy link
Author

jjb commented Apr 10, 2013

@samphippen nice. i wonder why ruby 2 caused that behavior to change thought...

@myronmarston
Copy link
Member

@jjb: it got changed here:

http://bugs.ruby-lang.org/issues/4438

@jjb
Copy link
Author

jjb commented Apr 10, 2013

interesting ​-- although i can't really tell from that thread what the
decided behavior change was.

i haven't seen this issue discussed anywhere else on the web

/cc @avdi

@avdi
Copy link

avdi commented Apr 10, 2013

Well that ticks me off. I can't think of any good reason to require that thing to be a class or module.

@JonRowe
Copy link
Member

JonRowe commented Apr 12, 2013

So this'll be fixed when #236 is merged, which will be fixed when #239 is merged? :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants