had additional files that were moved earlier
This commit is contained in:
parent
01cf6cea80
commit
be82666a95
@ -1,82 +0,0 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
||||||
|
|
||||||
require "webrat/mechanize"
|
|
||||||
|
|
||||||
describe Webrat::MechanizeSession do
|
|
||||||
|
|
||||||
before :each do
|
|
||||||
Webrat.configuration.mode = :mechanize
|
|
||||||
end
|
|
||||||
|
|
||||||
before(:each) do
|
|
||||||
@mech = Webrat::MechanizeSession.new
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "headers method" do
|
|
||||||
it "should return empty headers for a newly initialized session" do
|
|
||||||
@mech.headers.should == {}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "post" do
|
|
||||||
def url
|
|
||||||
'http://test.host/users'
|
|
||||||
end
|
|
||||||
|
|
||||||
def data
|
|
||||||
{:user => {:first_name => 'Nancy', :last_name => 'Callahan'}}
|
|
||||||
end
|
|
||||||
|
|
||||||
def flattened_data
|
|
||||||
{'user[first_name]' => 'Nancy', 'user[last_name]' => 'Callahan'}
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should flatten model post data" do
|
|
||||||
mechanize = mock(:mechanize)
|
|
||||||
WWW::Mechanize.stub!(:new => mechanize)
|
|
||||||
mechanize.should_receive(:post).with(url, flattened_data)
|
|
||||||
Webrat::MechanizeSession.new.post(url, data)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#absolute_url" do
|
|
||||||
before(:each) do
|
|
||||||
@session = Webrat::MechanizeSession.new
|
|
||||||
@session.stub!(:current_url).and_return(absolute_url)
|
|
||||||
end
|
|
||||||
|
|
||||||
def absolute_url
|
|
||||||
'http://test.host/users/fred/cabbages'
|
|
||||||
end
|
|
||||||
|
|
||||||
def rooted_url
|
|
||||||
'/users/fred/cabbages'
|
|
||||||
end
|
|
||||||
|
|
||||||
def relative_url
|
|
||||||
'../../wilma'
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return unmodified url if prefixed with scheme" do
|
|
||||||
@session.absolute_url(absolute_url).should == absolute_url
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should prefix scheme and hostname if url begins with /" do
|
|
||||||
@session.absolute_url(rooted_url).should == absolute_url
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should resolve sibling URLs relative to current path" do
|
|
||||||
@session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should cope with sibling URLs from root of site" do
|
|
||||||
@session.stub!(:current_url).and_return('http://test.host')
|
|
||||||
@session.absolute_url(relative_url).should == 'http://test.host/wilma'
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should cope with https" do
|
|
||||||
@session.stub!(:current_url).and_return('https://test.host')
|
|
||||||
@session.absolute_url(relative_url).should == 'https://test.host/wilma'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,42 +0,0 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
|
|
||||||
|
|
||||||
require "webrat/merb"
|
|
||||||
|
|
||||||
describe Webrat::MerbSession do
|
|
||||||
it "should not pass empty params if data is and empty hash" do
|
|
||||||
session = Webrat::MerbSession.new
|
|
||||||
response = OpenStruct.new
|
|
||||||
response.status = 200
|
|
||||||
session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
|
|
||||||
session.get('url', {}, nil)
|
|
||||||
end
|
|
||||||
|
|
||||||
%w{post put delete}.each do |request_method|
|
|
||||||
it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
|
|
||||||
session = Webrat::MerbSession.new
|
|
||||||
response = OpenStruct.new
|
|
||||||
response.status = 200
|
|
||||||
|
|
||||||
session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
|
|
||||||
session.send(request_method, 'url', {}, nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "a session with a response" do
|
|
||||||
setup do
|
|
||||||
@session = Webrat::MerbSession.new
|
|
||||||
@response = OpenStruct.new
|
|
||||||
@response.status = 200
|
|
||||||
@response.body = 'test response'
|
|
||||||
@session.instance_variable_set(:@response, @response)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return body of a request as a response_body" do
|
|
||||||
@session.response_body.should == @response.body
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should return status of a request as a response_code" do
|
|
||||||
@session.response_code.should == @response.status
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -1,10 +0,0 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
||||||
require "active_support"
|
|
||||||
|
|
||||||
silence_warnings do
|
|
||||||
require "action_controller"
|
|
||||||
require "action_controller/integration"
|
|
||||||
end
|
|
||||||
|
|
||||||
require "webrat/rails"
|
|
||||||
Webrat.configuration.mode_for_test = :rails
|
|
@ -1,94 +0,0 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|
||||||
|
|
||||||
require "webrat/rails"
|
|
||||||
|
|
||||||
describe Webrat::RailsSession do
|
|
||||||
before do
|
|
||||||
Webrat.configuration.mode = :rails
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should delegate response_body to the session response body" do
|
|
||||||
response = mock("response", :body => "<html>")
|
|
||||||
integration_session = mock("integration session", :response => response)
|
|
||||||
Webrat::RailsSession.new(integration_session).response_body.should == "<html>"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should delegate response_code to the session response code" do
|
|
||||||
response = mock("response", :code => "42")
|
|
||||||
integration_session = mock("integration session", :response => response)
|
|
||||||
Webrat::RailsSession.new(integration_session).response_code.should == 42
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should delegate get to request_via_redirect on the integration session" do
|
|
||||||
integration_session = mock("integration session")
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:get, "url", "data", "headers")
|
|
||||||
rails_session.get("url", "data", "headers")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should delegate post to request_via_redirect on the integration session" do
|
|
||||||
integration_session = mock("integration session")
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:post, "url", "data", "headers")
|
|
||||||
rails_session.post("url", "data", "headers")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should delegate put to request_via_redirect on the integration session" do
|
|
||||||
integration_session = mock("integration session")
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:put, "url", "data", "headers")
|
|
||||||
rails_session.put("url", "data", "headers")
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should delegate delete to request_via_redirect on the integration session" do
|
|
||||||
integration_session = mock("integration session")
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:delete, "url", "data", "headers")
|
|
||||||
rails_session.delete("url", "data", "headers")
|
|
||||||
end
|
|
||||||
|
|
||||||
context "the URL is a full path" do
|
|
||||||
it "should just pass on the path" do
|
|
||||||
integration_session = mock("integration session", :https! => nil)
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
|
||||||
rails_session.get("http://www.example.com/url", "data", "headers")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "the URL is https://" do
|
|
||||||
it "should call #https! with true before the request and just pass on the path" do
|
|
||||||
integration_session = mock("integration session")
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:https!).with(true)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
|
||||||
rails_session.get("https://www.example.com/url", "data", "headers")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "the URL is http://" do
|
|
||||||
it "should call #https! with true before the request" do
|
|
||||||
integration_session = mock("integration session", :request_via_redirect => nil)
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:https!).with(false)
|
|
||||||
rails_session.get("http://www.example.com/url", "data", "headers")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "the URL include an anchor" do
|
|
||||||
it "should strip out the anchor" do
|
|
||||||
integration_session = mock("integration session", :https! => false)
|
|
||||||
rails_session = Webrat::RailsSession.new(integration_session)
|
|
||||||
integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
|
|
||||||
rails_session.get("http://www.example.com/url#foo", "data", "headers")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should provide a saved_page_dir" do
|
|
||||||
Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should provide a doc_root" do
|
|
||||||
Webrat::RailsSession.new(mock("integration session")).should respond_to(:doc_root)
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Reference in New Issue
Block a user