/usr/share/doc/ruby-rspec-expectations/features/built_in_matchers/throw_symbol.feature is in ruby-rspec-expectations 3.4.0c3e0m1s1-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 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:
```ruby
expect { throw :foo }.to throw_symbol
```
You'll often want to specify that a particular symbol is thrown:
```ruby
expect { throw :foo }.to throw_symbol(:foo)
```
If you care about the additional argument given to throw, you can specify that as well:
```ruby
expect { throw :foo, 7 }.to throw_symbol(:foo, 7)
```
Scenario: basic usage
Given a file named "throw_symbol_matcher_spec.rb" with:
"""ruby
RSpec.describe "throw" do
specify { expect { throw :foo }.to throw_symbol }
specify { expect { throw :bar, 7 }.to throw_symbol }
specify { expect { 5 + 5 }.not_to throw_symbol }
# deliberate failures
specify { expect { throw :foo }.not_to throw_symbol }
specify { expect { throw :bar, 7 }.not_to 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
RSpec.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 }.not_to throw_symbol(:foo) }
specify { expect { throw :bar }.not_to throw_symbol(:foo) }
# deliberate failures
specify { expect { throw :foo }.not_to throw_symbol(:foo) }
specify { expect { throw :foo, 7 }.not_to 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
RSpec.describe "throw symbol with argument" do
specify { expect { throw :foo, 7 }.to throw_symbol(:foo, 7) }
specify { expect { throw :foo, 8 }.not_to throw_symbol(:foo, 7) }
specify { expect { throw :bar, 7 }.not_to throw_symbol(:foo, 7) }
specify { expect { throw :foo }.not_to throw_symbol(:foo, 7) }
# deliberate failures
specify { expect { throw :foo, 7 }.not_to 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 |
|