diff --git a/spec/webrat/merb/indifferent_access_spec.rb b/spec/webrat/merb/indifferent_access_spec.rb new file mode 100644 index 0000000..9a92c6d --- /dev/null +++ b/spec/webrat/merb/indifferent_access_spec.rb @@ -0,0 +1,48 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") +require File.expand_path(File.dirname(__FILE__) + "/helper") + +describe HashWithIndifferentAccess do + it "should not update constructor when not a hash" do + HashWithIndifferentAccess.should_receive(:update).never + HashWithIndifferentAccess.new('test') + end + + it "should get the default for key" do + h = HashWithIndifferentAccess.new(:test => 'me') + h.should_receive(:super).never + + h.default(:test).should == 'me' + end + + context "a hash with a test value applied" do + + setup do + @h = HashWithIndifferentAccess.new + @h[:test] = 'me' + end + + it "should assign a new value" do + @h[:test].should == 'me' + end + + it "should return true if asked for existing key" do + @h.key?(:test).should be_true + end + + it "should return array of values for keys" do + @h.values_at(:test).should == ['me'] + end + + it "should merge with another hash" do + another = HashWithIndifferentAccess.new(:value => 'test') + @h.merge(another).values_at(:test, :value).should == ['me','test'] + end + + it "should delete the key" do + @h.delete(:test) + @h.any?.should be_false + @h[:test].should be_nil + end + + end +end \ No newline at end of file diff --git a/spec/webrat/merb/session_spec.rb b/spec/webrat/merb/session_spec.rb new file mode 100644 index 0000000..00f6021 --- /dev/null +++ b/spec/webrat/merb/session_spec.rb @@ -0,0 +1,43 @@ +require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") +require File.expand_path(File.dirname(__FILE__) + "/helper") + +describe Webrat::Session do + + it "should not pass empty params if data is and empty hash" do + session = Webrat::Session.new + response = OpenStruct.new + response.status = 200 + session.should_receive(:request).with('url', {:params=>{}, :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::Session.new + response = OpenStruct.new + response.status = 200 + + session.should_receive(:request).with('url', {:params=>{}, :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::Session.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 \ No newline at end of file