Sha256: ab87ce330a5e4d2ae454033b010345e0798b6af1987dfe3816191d04796faa56

Contents?: true

Size: 1.47 KB

Versions: 10

Compression:

Stored size: 1.47 KB

Contents

module Spec
  module Rails
    module Matchers
    
      class HaveText  #:nodoc:

        def initialize(expected)
          @expected = expected
        end

        def matches?(response_or_text)
          @actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
          return actual =~ expected if Regexp === expected
          return actual == expected unless Regexp === expected
        end
      
        def failure_message
          "expected #{expected.inspect}, got #{actual.inspect}"
        end
        
        def negative_failure_message
          "expected not to have text #{expected.inspect}"
        end
        
        def description
          "have text #{expected.inspect}"
        end
      
        private
          attr_reader :expected
          attr_reader :actual

      end

      # :call-seq:
      #   response.should have_text(expected)
      #   response.should_not have_text(expected)
      #
      # Accepts a String or a Regexp, matching a String using ==
      # and a Regexp using =~.
      #
      # If response_or_text has a #body, then that is used as to match against
      # else it uses response_or_text
      #
      # Use this instead of <tt>response.should have_tag()</tt>
      # when you want to match the whole string or whole body
      #
      # == Examples
      #
      #   response.should have_text("This is the expected text")
      def have_text(text)
        HaveText.new(text)
      end
    
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
dchelimsky-rspec-rails-1.1.99.1 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.2 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.3 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.4 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.5 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.6 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.7 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.8 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.99.9 lib/spec/rails/matchers/have_text.rb
mcmire-rspec-rails-1.1.99.9 lib/spec/rails/matchers/have_text.rb