Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created April 28, 2009 13:24
Show Gist options
  • Save dchelimsky/103147 to your computer and use it in GitHub Desktop.
Save dchelimsky/103147 to your computer and use it in GitHub Desktop.
# excerpted from spec/spec/matchers/raise_error_spec.rb
it "passes the error to the block" do
error = nil
lambda { non_existent_method }.should raise_error {|e|
error = e
}
error.should be_an_instance_of(NameError)
end
it "should fail if named error is raised" do
lambda {
lambda { non_existent_method }.should_not raise_error(NameError)
}.should fail_with(/expected no NameError, got #<NameError: undefined/)
end
1)
'should raise_error {|err| ... } passes the error to the block' FAILED
expected #<NoMethodError: undefined method `non_existent_method' for #<Spec::Example::ExampleGroup::Subclass_158:0xc08873>> to be an instance of NameError
/Users/david/projects/ruby/rspec-dev/example_rails_app/vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb:29:
2)
'should_not raise_error(NamedError) should fail if named error is raised' FAILED
expected Spec::Expectations::ExpectationNotMetError with message matching /expected no NameError, got #<NameError: undefined/, got #<Spec::Expectations::ExpectationNotMetError: expected no NameError, got #<NoMethodError: undefined method `non_existent_method' for #<Spec::Example::ExampleGroup::Subclass_163:0x2774a4>>>
/Users/david/projects/ruby/rspec-dev/example_rails_app/vendor/plugins/rspec/spec/spec/matchers/raise_error_spec.rb:120:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment