Sha256: 04182409db9f4115f5ab63d236faa6cac4567f2750963776f6ca843b18ea6784

Contents?: true

Size: 1.47 KB

Versions: 47

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 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 =~.
      #
      # 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

47 entries across 47 versions & 8 rubygems

Version Path
dchelimsky-rspec-rails-1.1.10 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.1 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.2 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.3 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.4 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.5 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.6 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11.7 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.11 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.12 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.6 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.7 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.8 lib/spec/rails/matchers/have_text.rb
dchelimsky-rspec-rails-1.1.9 lib/spec/rails/matchers/have_text.rb
jcnetdev-rspec-rails-1.1.5 lib/spec/rails/matchers/have_text.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/have_text.rb
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb