Blob of include_text.diff (raw blob data)

1 ÿþIndex: rspec_on_rails/lib/spec/rails/matchers/have_text.rb
2 ===================================================================
3 --- rspec_on_rails/lib/spec/rails/matchers/have_text.rb (revision 3333)
4 +++ rspec_on_rails/lib/spec/rails/matchers/have_text.rb (working copy)
5 @@ -39,9 +39,11 @@
6 # Accepts a String or a Regexp, matching a String using ==
7 # and a Regexp using =~.
8 #
9 + # If response_or_text has a #body, then that is used as to match against
10 + # else it uses response_or_text
11 + #
12 # Use this instead of <tt>response.should have_tag()</tt>
13 - # when you either don't know or don't care where on the page
14 - # this text appears.
15 + # when you want to match the whole string or whole body
16 #
17 # == Examples
18 #
19 Index: rspec_on_rails/lib/spec/rails/matchers/include_text.rb
20 ===================================================================
21 --- rspec_on_rails/lib/spec/rails/matchers/include_text.rb (revision 0)
22 +++ rspec_on_rails/lib/spec/rails/matchers/include_text.rb (revision 0)
23 @@ -0,0 +1,54 @@
24 +module Spec
25 + module Rails
26 + module Matchers
27 +
28 + class IncludeText #:nodoc:
29 +
30 + def initialize(expected)
31 + @expected = expected
32 + end
33 +
34 + def matches?(response_or_text)
35 + @actual = response_or_text.respond_to?(:body) ? response_or_text.body : response_or_text
36 + return actual.include?(expected)
37 + end
38 +
39 + def failure_message
40 + "expected to find #{expected.inspect} in #{actual.inspect}"
41 + end
42 +
43 + def negative_failure_message
44 + "expected not to include text #{expected.inspect}"
45 + end
46 +
47 + def to_s
48 + "include text #{expected.inspect}"
49 + end
50 +
51 + private
52 + attr_reader :expected
53 + attr_reader :actual
54 +
55 + end
56 +
57 +
58 + # :call-seq:
59 + # response.should include_text(expected)
60 + # response.should_not include_text(expected)
61 + #
62 + # Accepts a String, matching using include?
63 + #
64 + # Use this instead of <tt>response.should have_text()</tt>
65 + # when you either don't know or don't care where on the page
66 + # this text appears.
67 + #
68 + # == Examples
69 + #
70 + # response.should include_text("This text will be in the actual string")
71 + def include_text(text)
72 + IncludeText.new(text)
73 + end
74 +
75 + end
76 + end
77 +end
78 Index: rspec_on_rails/lib/spec/rails/version.rb
79 ===================================================================
80 --- rspec_on_rails/lib/spec/rails/version.rb (revision 3333)
81 +++ rspec_on_rails/lib/spec/rails/version.rb (working copy)
82 @@ -1,7 +1,7 @@
83 module Spec
84 module Rails
85 module VERSION #:nodoc:
86 - BUILD_TIME_UTC = 20080309210001
87 + BUILD_TIME_UTC = 20080315225339
88 end
89 end
90 end
91 Index: rspec_on_rails/spec/rails/matchers/include_text_spec.rb
92 ===================================================================
93 --- rspec_on_rails/spec/rails/matchers/include_text_spec.rb (revision 0)
94 +++ rspec_on_rails/spec/rails/matchers/include_text_spec.rb (revision 0)
95 @@ -0,0 +1,77 @@
96 +require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
97 +
98 +describe "include_text" do
99 +
100 + describe "where target is a Regexp" do
101 + it 'should should match submitted text using a regexp' do
102 + string = 'foo'
103 + string.should include_text(/fo*/)
104 + end
105 + end
106 +
107 + describe "where target is a String" do
108 + it 'should match submitted text using a string' do
109 + string = 'foo'
110 + string.should include_text('foo')
111 + end
112 +
113 + it 'should match if the text is contained' do
114 + string = 'I am a big piece of text'
115 + string.should include_text('big piece')
116 + end
117 +
118 + it 'should not match if text is not contained' do
119 + string = 'I am a big piece of text'
120 + string.should_not include_text('corey')
121 + end
122 + end
123 +
124 +end
125 +
126 +describe "include_text",
127 + :type => :controller do
128 + ['isolation','integration'].each do |mode|
129 + if mode == 'integration'
130 + integrate_views
131 + end
132 +
133 + describe "where target is a response (in #{mode} mode)" do
134 + controller_name :render_spec
135 +
136 + it "should pass with exactly matching text" do
137 + post 'text_action'
138 + response.should include_text("this is the text for this action")
139 + end
140 +
141 + it 'should pass with substring matching text' do
142 + post 'text_action'
143 + response.should include_text('text for this')
144 + end
145 +
146 + it "should pass with matching text (using Regexp)" do
147 + post 'text_action'
148 + response.should include_text(/is the text/)
149 + end
150 +
151 + it "should fail with matching text" do
152 + post 'text_action'
153 + lambda {
154 + response.should include_text("this is NOT the text for this action")
155 + }.should fail_with("expected \"this is NOT the text for this action\", got \"this is the text for this action\"")
156 + end
157 +
158 + it "should fail when a template is rendered" do
159 + post 'some_action'
160 + lambda {
161 + response.should include_text("this is the text for this action")
162 + }.should fail_with(/expected \"this is the text for this action\", got .*/)
163 + end
164 +
165 + it "should pass using should_not with incorrect text" do
166 + post 'text_action'
167 + response.should_not include_text("the accordian guy")
168 + end
169 + end
170 + end
171 +end
172 +
173 Index: rspec/lib/spec/version.rb
174 ===================================================================
175 --- rspec/lib/spec/version.rb (revision 3333)
176 +++ rspec/lib/spec/version.rb (working copy)
177 @@ -6,7 +6,7 @@
178 TINY = 3
179 RELEASE_CANDIDATE = nil
180
181 - BUILD_TIME_UTC = 20080309210001
182 + BUILD_TIME_UTC = 20080315225339
183
184 STRING = [MAJOR, MINOR, TINY].join('.')
185 TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
186