Class: Surrogate::RSpec::WithFilter::BlockAsserter
- Inherits:
-
Object
- Object
- Surrogate::RSpec::WithFilter::BlockAsserter
- Defined in:
- lib/surrogate/rspec/block_asserter.rb,
lib/surrogate/rspec/block_asserter.rb
Defined Under Namespace
Classes: RaiseAsserter
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #arity(n) ⇒ Object
- #before(&block) ⇒ Object
- #call_with(*args, &block) ⇒ Object
-
#initialize(definition_block) ⇒ BlockAsserter
constructor
A new instance of BlockAsserter.
- #matches?(block_to_test) ⇒ Boolean
-
#raising(arg, message = nil) ⇒ Object
arg can be a string (expected message) a regex (matches the actual message) an exception (type of exception expected to be raised).
- #returns(value = nil, &block) ⇒ Object
Constructor Details
#initialize(definition_block) ⇒ BlockAsserter
Returns a new instance of BlockAsserter.
51 52 53 54 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 51 def initialize(definition_block) @call_with = Invocation.new [] definition_block.call self end |
Instance Method Details
#after(&block) ⇒ Object
68 69 70 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 68 def after(&block) @after = block end |
#arity(n) ⇒ Object
79 80 81 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 79 def arity(n) @arity = n end |
#before(&block) ⇒ Object
64 65 66 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 64 def before(&block) @before = block end |
#call_with(*args, &block) ⇒ Object
56 57 58 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 56 def call_with(*args, &block) @call_with = Invocation.new args, &block end |
#matches?(block_to_test) ⇒ Boolean
83 84 85 86 87 88 89 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 83 def matches?(block_to_test) matches = before_matches? block_to_test matches &&= return_value_matches? block_to_test matches &&= arity_matches? block_to_test matches &&= after_matches? block_to_test matches end |
#raising(arg, message = nil) ⇒ Object
arg can be a string (expected message)
a regex (matches the actual )
an exception (type of exception expected to be raised)
75 76 77 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 75 def raising(arg, =nil) @raising = RaiseAsserter.new arg, end |
#returns(value = nil, &block) ⇒ Object
60 61 62 |
# File 'lib/surrogate/rspec/block_asserter.rb', line 60 def returns(value=nil, &block) @returns = block || lambda { |returned| returned.should == value } end |