Class: RSpec::FileMatchers::GenerateFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_for_generators/matchers/file/generate_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relative_path, type = nil) ⇒ GenerateFile

Returns a new instance of GenerateFile.



12
13
14
# File 'lib/rspec_for_generators/matchers/file/generate_file.rb', line 12

def initialize(relative_path, type = nil)
  @relative_path = relative_rails_file(relative_path, type)
end

Instance Attribute Details

#relative_pathObject

Returns the value of attribute relative_path.



10
11
12
# File 'lib/rspec_for_generators/matchers/file/generate_file.rb', line 10

def relative_path
  @relative_path
end

Instance Method Details

#failure_messageObject



28
29
30
# File 'lib/rspec_for_generators/matchers/file/generate_file.rb', line 28

def failure_message
  "Expected file #{relative_path} to have been generated, but it was not"
end

#matches?(generator, &block) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rspec_for_generators/matchers/file/generate_file.rb', line 16

def matches?(generator, &block)              
  file = File.expand_path(relative_path, generator.class.destination_root)
  file_exists = File.exists?(file)
  if block && file_exists
    read = File.read(file)
    ruby_content = read.extend(RSpec::RubyContent::Helpers)
    yield ruby_content
  else
    file_exists
  end        
end

#negative_failure_messageObject



32
33
34
# File 'lib/rspec_for_generators/matchers/file/generate_file.rb', line 32

def negative_failure_message
  "Did not expected file #{relative_path} to have been generated, but it was"
end