Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec_on_rails / lib / spec / rails / matchers / have_text.rb
blob5e4324107a17a51ba2fc01522fde30e76f17653f
1 module Spec
2   module Rails
3     module Matchers
4     
5       class HaveText  #:nodoc:
7         def initialize(expected)
8           @expected = expected
9         end
11         def matches?(response)
12           @actual = response.body
13           return actual =~ expected if Regexp === expected
14           return actual == expected unless Regexp === expected
15         end
16       
17         def failure_message
18           "expected #{expected.inspect}, got #{actual.inspect}"
19         end
20         
21         def negative_failure_message
22           "expected not to have text #{expected.inspect}"
23         end
24         
25         def to_s
26           "have text #{expected.inspect}"
27         end
28       
29         private
30           attr_reader :expected
31           attr_reader :actual
33       end
35       # :call-seq:
36       #   response.should have_text(expected)
37       #   response.should_not have_text(expected)
38       #
39       # Accepts a String or a Regexp, matching a String using ==
40       # and a Regexp using =~.
41       #
42       # Use this instead of <tt>response.should have_tag()</tt>
43       # when you either don't know or don't care where on the page
44       # this text appears.
45       #
46       # == Examples
47       #
48       #   response.should have_text("This is the expected text")
49       def have_text(text)
50         HaveText.new(text)
51       end
52     
53     end
54   end
55 end