Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

86 lines (72 sloc) 3.8 kb
Feature: throw_symbol matcher
The throw_symbol matcher is used to specify that a block of code
throws a symbol. The most basic form passes if any symbol is thrown:
expect { throw :foo }.to throw_symbol
You'll often want to specify that a particular symbol is thrown:
expect { throw :foo }.to throw_symbol(:foo)
If you care about the additional argument given to throw, you can
specify that as well:
expect { throw :foo, 7 }.to throw_symbol(:foo, 7)
Scenario: basic usage
Given a file named "throw_symbol_matcher_spec.rb" with:
"""ruby
describe "throw" do
specify { expect { throw :foo }.to throw_symbol }
specify { expect { throw :bar, 7 }.to throw_symbol }
specify { expect { 5 + 5 }.to_not throw_symbol }
# deliberate failures
specify { expect { throw :foo }.to_not throw_symbol }
specify { expect { throw :bar, 7 }.to_not throw_symbol }
specify { expect { 5 + 5 }.to throw_symbol }
end
"""
When I run `rspec throw_symbol_matcher_spec.rb`
Then the output should contain all of these:
| 6 examples, 3 failures |
| expected no Symbol to be thrown, got :foo |
| expected no Symbol to be thrown, got :bar |
| expected a Symbol to be thrown, got nothing |
Scenario: specify thrown symbol
Given a file named "throw_symbol_matcher_spec.rb" with:
"""ruby
describe "throw symbol" do
specify { expect { throw :foo }.to throw_symbol(:foo) }
specify { expect { throw :foo, 7 }.to throw_symbol(:foo) }
specify { expect { 5 + 5 }.to_not throw_symbol(:foo) }
specify { expect { throw :bar }.to_not throw_symbol(:foo) }
# deliberate failures
specify { expect { throw :foo }.to_not throw_symbol(:foo) }
specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo) }
specify { expect { 5 + 5 }.to throw_symbol(:foo) }
specify { expect { throw :bar }.to throw_symbol(:foo) }
end
"""
When I run `rspec throw_symbol_matcher_spec.rb`
Then the output should contain all of these:
| 8 examples, 4 failures |
| expected :foo not to be thrown, got :foo |
| expected :foo not to be thrown, got :foo with 7 |
| expected :foo to be thrown, got nothing |
| expected :foo to be thrown, got :bar |
Scenario: specify thrown symbol and argument
Given a file named "throw_symbol_argument_matcher_spec.rb" with:
"""ruby
describe "throw symbol with argument" do
specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) }
specify { expect { throw :foo, 8 }.to_not throw_symbol(:foo, 7) }
specify { expect { throw :bar, 7 }.to_not throw_symbol(:foo, 7) }
specify { expect { throw :foo }.to_not throw_symbol(:foo, 7) }
# deliberate failures
specify { expect { throw :foo, 7 }.to_not throw_symbol(:foo, 7) }
specify { expect { throw :foo, 8 }.to throw_symbol(:foo, 7) }
specify { expect { throw :bar, 7 }.to throw_symbol(:foo, 7) }
specify { expect { throw :foo }.to throw_symbol(:foo, 7) }
end
"""
When I run `rspec throw_symbol_argument_matcher_spec.rb`
Then the output should contain all of these:
| 8 examples, 4 failures |
| expected :foo with 7 not to be thrown, got :foo with 7 |
| expected :foo with 7 to be thrown, got :foo with 8 |
| expected :foo with 7 to be thrown, got :bar |
| expected :foo with 7 to be thrown, got :foo with no argument |
Jump to Line
Something went wrong with that request. Please try again.