Class: RSpec::RubyContentMatchers::HaveBlock
- Inherits:
-
RSpec::RubyContentMatcher
- Object
- RSpec::RubyContentMatcher
- RSpec::RubyContentMatchers::HaveBlock
- Defined in:
- lib/code_spec/matchers/have_block.rb
Defined Under Namespace
Modules: BlockArgs
Constant Summary
Constants inherited from RSpec::RubyContentMatcher
RSpec::RubyContentMatcher::ANY_GROUP, RSpec::RubyContentMatcher::LPAR, RSpec::RubyContentMatcher::OPT_ARGS, RSpec::RubyContentMatcher::OPT_SPACES, RSpec::RubyContentMatcher::Q_ANY_GROUP, RSpec::RubyContentMatcher::RPAR, RSpec::RubyContentMatcher::SPACES
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block_args ⇒ Object
readonly
Returns the value of attribute block_args.
-
#block_arguments ⇒ Object
readonly
Returns the value of attribute block_arguments.
-
#do_option ⇒ Object
readonly
Returns the value of attribute do_option.
-
#end_option ⇒ Object
readonly
Returns the value of attribute end_option.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from RSpec::RubyContentMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
- #handle_result(content, match, &block) ⇒ Object
-
#initialize(name, options = {}) ⇒ HaveBlock
constructor
A new instance of HaveBlock.
- #matches?(content, &block) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from RSpec::RubyContentMatcher
#any_args_expr, #args_msg, #comment_end, #debug, #debug?, #debug_content, #display, #display_content, #end_expr, #get_expr, #index, #is_match?, #opt
Constructor Details
#initialize(name, options = {}) ⇒ HaveBlock
Returns a new instance of HaveBlock.
5 6 7 8 9 10 11 |
# File 'lib/code_spec/matchers/have_block.rb', line 5 def initialize(name, ={}) super [:end] || name @name = name.to_s @args = [:args] @do_option = [:do].nil? ? true : [:do] @block_args = [:block_args] end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
3 4 5 |
# File 'lib/code_spec/matchers/have_block.rb', line 3 def args @args end |
#block_args ⇒ Object (readonly)
Returns the value of attribute block_args.
3 4 5 |
# File 'lib/code_spec/matchers/have_block.rb', line 3 def block_args @block_args end |
#block_arguments ⇒ Object (readonly)
Returns the value of attribute block_arguments.
3 4 5 |
# File 'lib/code_spec/matchers/have_block.rb', line 3 def block_arguments @block_arguments end |
#do_option ⇒ Object (readonly)
Returns the value of attribute do_option.
3 4 5 |
# File 'lib/code_spec/matchers/have_block.rb', line 3 def do_option @do_option end |
#end_option ⇒ Object (readonly)
Returns the value of attribute end_option.
3 4 5 |
# File 'lib/code_spec/matchers/have_block.rb', line 3 def end_option @end_option end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/code_spec/matchers/have_block.rb', line 3 def name @name end |
Instance Method Details
#failure_message ⇒ Object
46 47 48 49 |
# File 'lib/code_spec/matchers/have_block.rb', line 46 def super display "Expected there to be a block #{name}#{args_msg}#{block_args_msg}, but there wasn't" end |
#handle_result(content, match, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/code_spec/matchers/have_block.rb', line 35 def handle_result content, match, &block if block && match && content ruby_content = content.strip ruby_content.extend(BlockArgs) ruby_content.block_args = block_arguments yield ruby_content end match end |
#matches?(content, &block) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/code_spec/matchers/have_block.rb', line 21 def matches? content, &block @content = content blockargs = content.scan(/do\s+\|(.*?)\|/).flatten[0] @block_arguments = blockargs.split ',' if blockargs match = is_match? content content_to_yield = if indexes content_matches[indexes.first] || content_matches[indexes.last] else content_matches[index] end handle_result(content_to_yield, match, &block) end |
#negative_failure_message ⇒ Object
51 52 53 54 |
# File 'lib/code_spec/matchers/have_block.rb', line 51 def super display "Did not expect there to be a block #{name}#{args_msg}, but there was" end |