RichGuk (owner)

Fork Of

Revisions

gist: 18634 Download_button fork
public
Public Clone URL: git://gist.github.com/18634.git
home_spec.rb
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
given "logged in" do
  login
end
 
context "when logged in" do
  context "Homepage: url(:home)", :given => "logged in" do
    before(:each) do
      @rack = request(:home)
    end
    
    it "allows the user to visit" do
      @rack.should be_successful
      @rack.body.should == "Welcome"
    end
    
    it "returns an HTML page" do
      @rack.should have_content_type(:html)
    end
  end
end
 
context "when not logged in" do
  describe "Homepage: url(:home)" do
    it "redirects the user to the login screen" do
      requesting(:home).should redirect_to(:get_login)
    end
  end
end
login_spec.rb
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
describe "when logging in at '/'" do
  describe "the login form" do
    it "exists" do
      response_for("/").should have_xpath("//*")
    end
  
    it "POSTS to url(:login)" do
      response_for("/").should have_xpath("//form[@method='post'][@action='#{url(:login)}']")
    end
    
    it "has a text field named 'username'" do
      response_for("/").should have_xpath("//form/input[@name='username'][@type='text']")
    end
    
    it "has a password field named password" do
      response_for("/").should have_xpath("//form/input[@name='password'][@type='password']")
    end
  end
  
  it "redirects to '/' if the login was incorrect" do
    requesting("/", :method => "POST",
      :body_params => {:username => "wycats", :password => "bad"}).
    should redirect_to(:get_login)
  end
 
  it "logs in" do
    logging_in.should redirect_to(:home)
  end
end
spec_helper.rb
1
2
3
4
5
6
7
Merb::Test.add_helpers do
  def login
    rack = request("/", :method => "POST",
      :params => {:username => "wycats", :password => "pass"})
  end
  alias logging_in login
end