Class: RBeautifyMatchers::BeBlockStartLike

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-beautify/spec/spec_helper.rb

Overview

Adds more descriptive failure messages to the dynamic be_valid matcher

Instance Method Summary collapse

Constructor Details

#initialize(block_matcher_name, offset, match, after_match) ⇒ BeBlockStartLike

:nodoc:



13
14
15
16
17
18
19
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 13

def initialize(block_matcher_name, offset, match, after_match)
  # triggers the standard Spec::Matchers::Be magic, as if the original Spec::Matchers#method_missing had fired
  @block_matcher_name = block_matcher_name
  @offset = offset
  @match = match
  @after_match = after_match
end

Instance Method Details

#descriptionObject



43
44
45
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 43

def description
  "block start with"
end

#expected_stringObject



35
36
37
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 35

def expected_string
  "name: #{@block_matcher_name}, offset: #{@offset}, match: '#{@match}', after_match: '#{@after_match}'"
end

#failure_messageObject



27
28
29
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 27

def failure_message
  "expected\n#{expected_string} but got\n#{got_string}"
end

#got_stringObject



39
40
41
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 39

def got_string
  "name: #{@target_block.block_matcher.name}, offset: #{@target_block.offset}, match: '#{@target_block.match}', after_match: '#{@target_block.after_match}'"
end

#matches?(target_block) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 21

def matches?(target_block)
  @target_block = target_block
  return !target_block.nil? &&
    (expected_string == got_string)
end

#negative_failure_messageObject



31
32
33
# File 'lib/ruby-beautify/spec/spec_helper.rb', line 31

def negative_failure_message
  "expected to be different from #{expected_string}"
end