Blob of rspec_on_rails/spec/rails/matchers/include_text_spec.rb (raw blob data)

1 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
3 describe "include_text" do
4
5 describe "where target is a String" do
6 it 'should match submitted text using a string' do
7 string = 'foo'
8 string.should include_text('foo')
9 end
10
11 it 'should match if the text is contained' do
12 string = 'I am a big piece of text'
13 string.should include_text('big piece')
14 end
15
16 it 'should not match if text is not contained' do
17 string = 'I am a big piece of text'
18 string.should_not include_text('corey')
19 end
20 end
21
22 end
23
24 describe "include_text", :type => :controller do
25 ['isolation','integration'].each do |mode|
26 if mode == 'integration'
27 integrate_views
28 end
29
30 describe "where target is a response (in #{mode} mode)" do
31 controller_name :render_spec
32
33 it "should pass with exactly matching text" do
34 post 'text_action'
35 response.should include_text("this is the text for this action")
36 end
37
38 it 'should pass with substring matching text' do
39 post 'text_action'
40 response.should include_text('text for this')
41 end
42
43 it "should fail with matching text" do
44 post 'text_action'
45 lambda {
46 response.should include_text("this is NOT the text for this action")
47 }.should fail_with("expected to find \"this is NOT the text for this action\" in \"this is the text for this action\"")
48 end
49
50 it "should fail when a template is rendered" do
51 post 'some_action'
52 failure_message = case mode
53 when 'isolation'
54 /expected to find \"this is the text for this action\" in \"render_spec\/some_action\"/
55 when 'integration'
56 /expected to find \"this is the text for this action\" in \"\"/
57 end
58 lambda {
59 response.should include_text("this is the text for this action")
60 }.should fail_with(failure_message)
61 end
62
63 it "should pass using should_not with incorrect text" do
64 post 'text_action'
65 response.should_not include_text("the accordian guy")
66 end
67 end
68 end
69 end