Sha256: c5fd31682af8a1da255b93006e97a8d0a900dec25c3dd5df95d340d6360c2817

Contents?: true

Size: 1.26 KB

Versions: 47

Compression:

Stored size: 1.26 KB

Contents

module Spec
  module Rails
    module Matchers

      class IncludeText  #: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.include?(expected)
        end

        def failure_message
          "expected to find #{expected.inspect} in #{actual.inspect}"
        end

        def negative_failure_message
          "expected not to include text #{expected.inspect}"
        end

        def to_s
          "include text #{expected.inspect}"
        end

        private
          attr_reader :expected
          attr_reader :actual

      end


      # :call-seq:
      #   response.should include_text(expected)
      #   response.should_not include_text(expected)
      #
      # Accepts a String, matching using include?
      #
      # Use this instead of <tt>response.should have_text()</tt>
      # when you either don't know or don't care where on the page
      # this text appears.
      #
      # == Examples
      #
      #   response.should include_text("This text will be in the actual string")
      def include_text(text)
        IncludeText.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/include_text.rb
dchelimsky-rspec-rails-1.1.11.1 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11.2 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11.3 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11.4 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11.5 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11.6 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11.7 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.11 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.12 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.6 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.7 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.8 lib/spec/rails/matchers/include_text.rb
dchelimsky-rspec-rails-1.1.9 lib/spec/rails/matchers/include_text.rb
jcnetdev-rspec-rails-1.1.5 lib/spec/rails/matchers/include_text.rb
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/include_text.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/include_text.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/include_text.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec-rails/lib/spec/rails/matchers/include_text.rb
jstorimer-deep-test-2.0.0 sample_rails_project/vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/include_text.rb