public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://gitrdoc.com/brynary/webrat/tree/master/
Clone URL: git://github.com/brynary/webrat.git
webrat / spec / private / sinatra / sinatra_spec.rb
100644 43 lines (33 sloc) 1.499 kb
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
require File.expand_path(File.dirname(__FILE__) + '/helper')
 
describe Webrat::SinatraSession do
  before :each do
    Webrat.configuration.mode = :sinatra
    @sinatra_session = Webrat::SinatraSession.new
 
    @response = mock(:response)
    @response.stub!(:redirect?)
 
    @sinatra_session.instance_variable_set("@response", @response)
  end
 
  it "should delegate get to get_it" do
    @sinatra_session.should_receive(:get_it).with("url", { :env => "headers" })
    @sinatra_session.get("url", {}, "headers")
  end
 
  it "should delegate post to post_it" do
    @sinatra_session.should_receive(:post_it).with("url", { :env => "headers" })
    @sinatra_session.post("url", {}, "headers")
  end
 
  it "should delegate put to put_it" do
    @sinatra_session.should_receive(:put_it).with("url", { :env => "headers" })
    @sinatra_session.put("url", {}, "headers")
  end
 
  it "should delegate delete to delete_it" do
    @sinatra_session.should_receive(:delete_it).with("url", { :env => "headers" })
    @sinatra_session.delete("url", {}, "headers")
  end
 
  it "should forward headers when following redirects" do
    @response.should_receive(:redirect?).twice.and_return(true, false)
    @response.should_receive(:location).and_return("redirect url")
 
    @sinatra_session.should_receive(:get_it).with("original url", { :env => "headers" })
    @sinatra_session.should_receive(:get_it).with("redirect url", { :env => "headers" })
 
    @sinatra_session.get("original url", {}, "headers")
  end
end