Sha256: 2a02d3157fcbc7de0f4a80f48eee8a994f2434ae550fd4ae0417aafd1203b581

Contents?: true

Size: 1.3 KB

Versions: 6

Compression:

Stored size: 1.3 KB

Contents

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

        def initialize(expected)
          @expected = expected
        end

        def matches?(response)
          @actual = response.body
          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 to_s
          "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 =~.
      #
      # Use this instead of <tt>response.should have_tag()</tt>
      # when you either don't know or don't care where on the page
      # this text appears.
      #
      # == Examples
      #
      #   response.should have_text("This is the expected text")
      def have_text(text)
        HaveText.new(text)
      end
    
    end
  end
end

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
deckshuffler-0.0.2 vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb
has_finder-0.1.2 spec/rails/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb
has_finder-0.1.1 spec/rails/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb
has_finder-0.1.3 spec/rails/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb
typo-5.0.2 vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb
typo-5.0.1 vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb