Class: GenSpec::Matchers::ResultMatcher

Inherits:
Base
  • Object
show all
Defined in:
lib/genspec/matchers/result_matcher.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#args, #block, #destination_root, #error, #generator, #init_blocks

Instance Method Summary collapse

Methods inherited from Base

#match!, #matched?, #matches?, #source_root

Constructor Details

#initialize(filename, &block) ⇒ ResultMatcher

Returns a new instance of ResultMatcher.



6
7
8
9
# File 'lib/genspec/matchers/result_matcher.rb', line 6

def initialize(filename, &block)
  @filename = filename
  super(&block)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/genspec/matchers/result_matcher.rb', line 4

def filename
  @filename
end

Instance Method Details

#failure_messageObject



29
30
31
# File 'lib/genspec/matchers/result_matcher.rb', line 29

def failure_message
  "Expected to generate #{filename}"
end

#generatedObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/genspec/matchers/result_matcher.rb', line 11

def generated
  if filename
    path = File.join(destination_root, filename)
    if File.exist?(path)
      match!
      spec_file_contents(path)
    end
  else
    # there was no error, so in the context of
    # "should generate", it most certainly
    # generated.
    match!
    if block
      block.call
    end
  end
end

#negative_failure_messageObject



33
34
35
# File 'lib/genspec/matchers/result_matcher.rb', line 33

def negative_failure_message
  "Expected to not generate #{filename}"
end