Rspec View

Ruby code posted
created at 25 Aug 21:46

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require File.dirname(__FILE__) + "/../../spec_helper"

describe "/contacts/new" do
  it "should render the form" do
    assigns[:contact] = Contact.new
    
    render "/contacts/new.html.erb"
    
    response.should have_tag('form[action=?]','/contact/create') do
      with_tag('input[name=?]','contact[name]')
      with_tag('input[name=?]','contact[email]')
      with_tag('input[name=?]','contact[phone]')
      with_tag('input[name=?]','contact[message]')
    end
  end
  
  def expect_error_message_on(attribute)
    template.stub!(:error_message_on)
    assigns[:contact] = Contact.new
    template.should_receive(:error_message_on).with(assigns[:contact], attribute).and_return("message received")
  end
  
  it "should ask for error messages for name" do
    expect_error_message_on(:name)
    
    render "/contacts/new.html.erb"
    
    response.should include_text("message received")
  end
  
  it "should ask for error messages for email" do
    expect_error_message_on(:email)
    
    render "/contacts/new.html.erb"
    
    response.should include_text("message received")
  end
  
  it "should ask for error messages for phone" do
    expect_error_message_on(:phone)
    
    render "/contacts/new.html.erb"
    
    response.should include_text("message received")
  end
  
  it "should ask for error messages for message" do
    expect_error_message_on(:message)
    
    render "/contacts/new.html.erb"
    
    response.should include_text("message received")
  end

end
1.52 KB in 3 ms with coderay