changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec_on_rails/lib/spec/rails/matchers/have_text.rb

changeset 16: 01fd3f10ae84
author: moriq@moriq.com
date: Mon Mar 10 10:13:18 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec_on_rails
1module Spec
2 module Rails
3 module Matchers
4
5 class HaveText #:nodoc:
6
7 def initialize(expected)
8 @expected = expected
9 end
10
11 def matches?(response_or_text)
12 @actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
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
32
33 end
34
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
55end