Class: RSpec::RailsApp::Content::Matchers::HaveGem
- Inherits:
-
Object
- Object
- RSpec::RailsApp::Content::Matchers::HaveGem
- Extended by:
- RailsAssist::UseMacro
- Includes:
- RailsAssist::File::Special
- Defined in:
- lib/rails_app_spec/matchers/special/have_gem.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(*args) ⇒ HaveGem
constructor
A new instance of HaveGem.
-
#matches?(root_path = nil) ⇒ Boolean
TODO: relative to root_path ?.
- #msg ⇒ Object
- #name_expr ⇒ Object
- #negative_failure_message ⇒ Object
- #version_expr ⇒ Object
- #version_txt ⇒ Object
Constructor Details
#initialize(*args) ⇒ HaveGem
Returns a new instance of HaveGem.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 16 def initialize *args raise ArgumentException, "First argument must name the gem" if !args.first.kind_of_label? @name = args.delete_at(0) return if args.size == 0 || !args[1].kind_of_label? @version = args.delete_at(1) @options = {} return if args.empty? raise ArgumentException, "Last argument of gem statement must be a n options Hash" if !args.last.kind_of? Hash @options = args.last end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 14 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 14 def @options end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
14 15 16 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 14 def version @version end |
Instance Method Details
#failure_message ⇒ Object
52 53 54 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 52 def "Expected #{msg}" end |
#matches?(root_path = nil) ⇒ Boolean
TODO: relative to root_path ?
30 31 32 33 34 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 30 def matches?(root_path=nil) content = read_gem_file return nil if content.empty? (content =~ /gem\s+#{name_expr}#{version_expr}/) end |
#msg ⇒ Object
44 45 46 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 44 def msg "the Gemfile to have a gem statement: gem '#{name}'#{version_txt}'" end |
#name_expr ⇒ Object
36 37 38 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 36 def name_expr "('|\")" + name + '\1' end |
#negative_failure_message ⇒ Object
56 57 58 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 56 def "Did not expect #{msg}" end |
#version_expr ⇒ Object
40 41 42 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 40 def version_expr '\s*,\s*' + "('|\")" + name + '\2' if version end |
#version_txt ⇒ Object
48 49 50 |
# File 'lib/rails_app_spec/matchers/special/have_gem.rb', line 48 def version_txt version ? ", '#{version}'" : "" end |