Class: GenSpec::Matchers::Base

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/genspec/matchers/base.rb', line 12

def initialize(&block)
  @block = block if block_given?
  @matched = false
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



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

def block
  @block
end

#destination_rootObject (readonly)

Returns the value of attribute destination_root.



5
6
7
# File 'lib/genspec/matchers/base.rb', line 5

def destination_root
  @destination_root
end

#errorObject

Returns the value of attribute error.



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

def error
  @error
end

#generatorObject (readonly)

Returns the value of attribute generator.



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

def generator
  @generator
end

#init_blocksObject (readonly)

Returns the value of attribute init_blocks.



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

def init_blocks
  @init_blocks
end

Instance Method Details

#failure_messageObject



52
53
54
# File 'lib/genspec/matchers/base.rb', line 52

def failure_message
  "was supposed to match and didn't"
end

#match!Object



17
18
19
# File 'lib/genspec/matchers/base.rb', line 17

def match!
  @matched = true
end

#matched?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/genspec/matchers/base.rb', line 48

def matched?
  @matched
end

#matches?(generator) ⇒ Boolean

Returns:

  • (Boolean)


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
# File 'lib/genspec/matchers/base.rb', line 21

def matches?(generator)
  @described = generator[:described]
  @args = generator[:args]
  @generator_options = generator[:generator_options]
  @shell = GenSpec::Shell.new(generator[:output] || "", generator[:input] || "")
  @init_blocks = generator[:init_blocks]
  
  if @described.kind_of?(Class)
    @generator = @described
  else
    if defined?(Rails)
      @generator = Rails::Generators.find_by_namespace(@described)
    else
      @generator = Thor::Util.find_by_namespace(@described)
    end
  end
  
  raise "Could not find generator: #{@described.inspect}" unless @generator
  
  inject_error_handlers!
  invoking
  invoke
  matched?
ensure
  complete
end

#negative_failure_messageObject



56
57
58
# File 'lib/genspec/matchers/base.rb', line 56

def negative_failure_message
  "was supposed to not match and did"
end

#source_rootObject



8
9
10
# File 'lib/genspec/matchers/base.rb', line 8

def source_root
  generator.source_root
end