Sha256: fe61878ba7efb19ddb67e568a659eab7bc962203ce0270717dcaad12bb147ce2

Contents?: true

Size: 1.4 KB

Versions: 10

Compression:

Stored size: 1.4 KB

Contents

# open application_file
# see if there is the config.[statement] = [expr]

module RSpec::RailsApp::Content
  module Matchers
    class HaveAppConfig
      extend Rails3::Assist::UseMacro
      use_helpers :file

      include Rails3::Assist::File::Special
      include Rails3::Assist::File::Application
    
      attr_reader :left_side, :right_side, :operator

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

      # TODO: relative to root_path ?
      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

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

      def msg
        "there to be the Application config statement '#{left_side} #{operator} #{right_side}' in config/application.rb"
      end
  
      def failure_message
        "Expected #{msg}" 
      end 
    
      def negative_failure_message
        super
        "Did not expect #{msg}" 
      end
    end
                    
    # config.autoload_paths += %W(#{Rails.root}/lib)
    # have_app_config :autoload_paths => '%W(#{Rails.root}/lib)', :op => '+='
    def have_app_config statement_hash
      HaveAppConfig.new statement_hash
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails-app-spec-0.3.2 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.3.1 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.3.0 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.16 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.15 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.14 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.13 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.12 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.10 lib/rails_app_spec/matchers/special/have_app_config.rb
rails-app-spec-0.2.8 lib/rails_app_spec/matchers/special/have_app_config.rb