Class: RSpec::RailsApp::Content::Matchers::HaveAppConfig

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ HaveAppConfig

Returns a new instance of HaveAppConfig.



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

def initialize args
  @left_side, @right_side = *args.first
  @operator = last_arg_value({:op => '='}, args)
end

Instance Attribute Details

#left_sideObject (readonly)

Returns the value of attribute left_side.



13
14
15
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 13

def left_side
  @left_side
end

#operatorObject (readonly)

Returns the value of attribute operator.



13
14
15
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 13

def operator
  @operator
end

#right_sideObject (readonly)

Returns the value of attribute right_side.



13
14
15
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 13

def right_side
  @right_side
end

Instance Method Details

#escape_all(*texts) ⇒ Object



28
29
30
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 28

def escape_all *texts
  texts.map{|t| Regexp.escape(t) }
end

#failure_messageObject



36
37
38
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 36

def failure_message
  "Expected #{msg}" 
end

#matches?(root_path = nil) ⇒ Boolean

TODO: relative to root_path ?

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 21

def matches?(root_path=nil)      
  content = read_application_file
  return nil if content.empty?      
  ls, rs, op = escape_all(left_side, right_side, operator)
  (content =~ /config.#{ls}\s*#{op}\s*#{rs}/)
end

#msgObject



32
33
34
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 32

def msg
  "there to be the Application config statement '#{left_side} #{operator} #{right_side}' in config/application.rb"
end

#negative_failure_messageObject



40
41
42
43
# File 'lib/rails_app_spec/matchers/special/have_app_config.rb', line 40

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