Class: RSpec::FileMatchers::GenerateFile

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

Instance Method Summary collapse

Constructor Details

#initialize(relative_path, type = nil) ⇒ GenerateFile

Returns a new instance of GenerateFile.



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

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

Instance Method Details

#failure_messageObject



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

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

#matches?(generator, &block) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#negative_failure_messageObject



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

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