Class: RSpec::RailsApp::Content::Matchers::HaveGems

Inherits:
Object
  • Object
show all
Extended by:
RailsAssist::UseMacro
Includes:
RailsAssist::File::Special
Defined in:
lib/rails_app_spec/matchers/special/have_gems.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*names) ⇒ HaveGems

Returns a new instance of HaveGems.



17
18
19
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 17

def initialize *names
  @names = names.to_strings
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 15

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



15
16
17
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 15

def names
  @names
end

Instance Method Details

#failure_messageObject



43
44
45
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 43

def failure_message
  "Expected #{msg}" 
end

#matches?(root_path = nil) ⇒ Boolean

TODO: relative to root_path ?

Returns:

  • (Boolean)


22
23
24
25
26
27
28
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 22

def matches?(root_path=nil)      
  content = read_gem_file
  return nil if content.empty?    
  names.each do |name|
    (content =~ /gem\s+#{name_expr(name)}/)
  end
end

#msgObject



35
36
37
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 35

def msg
  "the Gemfile to have a gem statement: gem '#{name}'"
end

#name_expr(gem_name) ⇒ Object



30
31
32
33
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 30

def name_expr gem_name
  @name = gem_name
  "('|\")" + gem_name + '\1'
end

#negative_failure_messageObject



47
48
49
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 47

def negative_failure_message
  "Did not expect #{msg}" 
end

#version_txtObject



39
40
41
# File 'lib/rails_app_spec/matchers/special/have_gems.rb', line 39

def version_txt
  version ? ", '#{version}'" : ""
end