0
+require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
0
+Merb.start :environment => 'test', :log_level => :fatal
0
+class TestController < Merb::Controller
0
+ attr_accessor :redirect_to
0
+ def redirect_action; redirect(@redirect_to || "/"); end
0
+ def success_action; end
0
+ def missing_action; render("i can has errorz", :status => 404); end
0
+describe Merb::Test::Rspec::ControllerMatchers do
0
+ include Merb::Test::ControllerHelper
0
+ Merb::Router.prepare do |r|
0
+ r.match("/redirect").to(:controller => "test_controller", :action => "redirect_action")
0
+ r.match("/success").to(:controller => "test_controller", :action => "success_action")
0
+ r.match("/missing").to(:controller => "test_controller", :action => "missing_action")
0
+ describe "#redirect" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :redirect_action).should redirect
0
+ it "should work with the result of a get helper call" do
0
+ get("/redirect").should redirect
0
+ it "should work with a redirection code" do
0
+ dispatch_to(TestController, :redirect_action).status.should redirect
0
+ describe "#redirect_to" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :redirect_action).should redirect_to("/")
0
+ dispatch_to(TestController, :redirect_action){ |controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
0
+ it "should work with the result of a get helper call" do
0
+ get("/redirect"){|controller| controller.redirect_to = "http://example.com/" }.should redirect_to("http://example.com/")
0
+ describe "#respond_successfully" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :success_action).should respond_successfully
0
+ it "should work with the result of a get helper call" do
0
+ get("/success").should respond_successfully
0
+ it "should work with a redirection code" do
0
+ dispatch_to(TestController, :success_action).status.should be_successful
0
+ describe "#be_missing" do
0
+ it "should work with the result of a dispatch_to helper call" do
0
+ dispatch_to(TestController, :missing_action).should be_missing
0
+ it "should work with the result of a get helper call" do
0
+ get("/missing").should be_client_error
0
+ it "should work with a redirection code" do
0
+ dispatch_to(TestController, :missing_action).status.should be_missing
0
+module Merb::Test::Rspec
0
+ module ControllerMatchers
0
+ class RedirectableTarget
0
+ attr_accessor :status, :headers
0
+ def initialize; @headers = {}; end
0
+ describe BeRedirect do
0
+ @target = RedirectableTarget.new
0
+ it "should match a 301 'Moved Permanently' redirect code" do
0
+ BeRedirect.new.matches?(301).should be_true
0
+ it "should match a 302 'Found' redirect code" do
0
+ BeRedirect.new.matches?(302).should be_true
0
+ it "should match a 303 'See Other' redirect code" do
0
+ BeRedirect.new.matches?(303).should be_true
0
+ it "should match a 304 'Not Modified' redirect code" do
0
+ BeRedirect.new.matches?(304).should be_true
0
+ it "should match a 307 'Temporary Redirect' redirect code" do
0
+ BeRedirect.new.matches?(307).should be_true
0
+ it "should match a target with a valid redirect code" do
0
+ BeRedirect.new.matches?(@target).should be_true
0
+ it "should not match a target with an unused redirect code" do
0
+ BeRedirect.new.matches?(@target).should_not be_true
0
+ it "should not match a target with a non redirect code" do
0
+ BeRedirect.new.matches?(@target).should_not be_true
0
+ describe "#failure_message" do
0
+ it "should be 'expected to redirect' when the target is a status code" do
0
+ matcher = BeRedirect.new
0
+ matcher.failure_message.should == "expected to redirect"
0
+ it "should be 'expected Foo#bar to redirect' when the target's controller is Foo and action is bar" do
0
+ matcher = BeRedirect.new
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to redirect"
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected not to redirect' when the target is a status code" do
0
+ matcher = BeRedirect.new
0
+ matcher.negative_failure_message.should == "expected not to redirect"
0
+ it "should be 'expected Foo#bar to redirect' when the target's controller is Foo and action is bar" do
0
+ matcher = BeRedirect.new
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to redirect"
0
+ describe RedirectTo do
0
+ @target = RedirectableTarget.new
0
+ it "should match a target if the status code is 300 level and the locations match" do
0
+ @target.headers['Location'] = "http://example.com/"
0
+ RedirectTo.new("http://example.com/").matches?(@target).should be_true
0
+ it "should not match a target if the status code is not 300 level but the locations match" do
0
+ @target.headers['Location'] = "http://example.com/"
0
+ RedirectTo.new("http://example.com/").matches?(@target).should_not be_true
0
+ it "should not match a target if the status code is 300 level but the locations do not match" do
0
+ @target.headers['Location'] = "http://merbivore.com/"
0
+ RedirectTo.new("http://example.com/").matches?(@target).should_not be_true
0
+ describe "#failure_message" do
0
+ it "should be 'expected Foo#bar to redirect to <http://expected.com/>, but was <http://target.com/>' when the expected url is http://expected.com/ and the target url is http://target.com/" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.headers['Location'] = "http://target.com/"
0
+ matcher = RedirectTo.new("http://expected.com/")
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to redirect to <http://expected.com/>, but was <http://target.com/>"
0
+ it "should be 'expected Foo#bar to redirect, but there was no redirection' when the target is not redirected" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.headers['Location'] = "http://target.com/"
0
+ matcher = RedirectTo.new("http://expected.com/")
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to redirect to <http://expected.com/>, but there was no redirection"
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected Foo#bar not to redirect to <http://expected.com/>, but it did anyways" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ @target.headers['Location'] = "http://target.com/"
0
+ matcher = RedirectTo.new("http://expected.com/")
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to redirect to <http://expected.com/>, but did anyway"
0
+ @target = RedirectableTarget.new
0
+ it "should match a target with a 200 'OK' status code" do
0
+ BeSuccess.new.matches?(200).should be_true
0
+ it "should match a target with a 201 'Created' status code" do
0
+ BeSuccess.new.matches?(201).should be_true
0
+ it "should match a target with a 202 'Accepted' status code" do
0
+ BeSuccess.new.matches?(202).should be_true
0
+ it "should match a target with a 203 'Non-Authoritative Information' status code" do
0
+ BeSuccess.new.matches?(203).should be_true
0
+ it "should match a target with a 204 'No Content' status code" do
0
+ BeSuccess.new.matches?(204).should be_true
0
+ it "should match a target with a 205 'Reset Content' status code" do
0
+ BeSuccess.new.matches?(205).should be_true
0
+ it "should match a target with a 206 'Partial Content' status code" do
0
+ BeSuccess.new.matches?(206).should be_true
0
+ it "should match a target with a 207 'Multi-Status' status code" do
0
+ BeSuccess.new.matches?(207).should be_true
0
+ it "should not match a target with an unused 200 level status code" do
0
+ BeSuccess.new.matches?(299).should_not be_true
0
+ it "should not match a target with a non 200 level status code" do
0
+ BeSuccess.new.matches?(301).should_not be_true
0
+ describe "#failure_message" do
0
+ it "should be 'expected to be successful but was 300' when the target is status code 300" do
0
+ matcher = BeSuccess.new
0
+ matcher.failure_message.should == "expected to be successful but was 300"
0
+ it "should be 'expected Foo#bar to be successful but was 404' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher = BeSuccess.new
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to be successful but was 404"
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected not to be successful but it was' when the target is a 200 status code" do
0
+ matcher = BeSuccess.new
0
+ matcher.negative_failure_message.should == "expected not to be successful but it was 200"
0
+ it "should be 'expected Foo#bar not to be successful but it was 200' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher = BeSuccess.new
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to be successful but it was 200"
0
+ @target = RedirectableTarget.new
0
+ it "should match a 400 'Bad Request'" do
0
+ BeMissing.new.matches?(400).should be_true
0
+ it "should match a 401 'Unauthorized'" do
0
+ BeMissing.new.matches?(401).should be_true
0
+ it "should match a 403 'Forbidden'" do
0
+ BeMissing.new.matches?(403).should be_true
0
+ it "should match a 404 'Not Found'" do
0
+ BeMissing.new.matches?(404).should be_true
0
+ it "should match a 409 'Conflict'" do
0
+ BeMissing.new.matches?(409).should be_true
0
+ it "should match a target with a valid client side error code" do
0
+ BeMissing.new.matches?(@target).should be_true
0
+ it "should not match a target with an unused client side error code" do
0
+ BeMissing.new.matches?(@target).should_not be_true
0
+ it "should not match a target with a non client side error code" do
0
+ BeMissing.new.matches?(@target).should_not be_true
0
+ describe "#failure_message" do
0
+ it "should be 'expected to be missing but was 300' when the target is status code 300" do
0
+ matcher = BeMissing.new
0
+ matcher.failure_message.should == "expected to be missing but was 300"
0
+ it "should be 'expected Foo#bar to be successful but was 301' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher = BeMissing.new
0
+ matcher.matches?(@target)
0
+ matcher.failure_message.should == "expected Foo#bar to be missing but was 301"
0
+ describe "#negative_failure_message" do
0
+ it "should be 'expected not to be successful but it was' when the target is a 400 status code" do
0
+ matcher = BeMissing.new
0
+ matcher.negative_failure_message.should == "expected not to be missing but it was 400"
0
+ it "should be 'expected Foo#bar not to be missing but it was 404' when the target is controller-ish" do
0
+ @target.stub!(:controller_name).and_return :Foo
0
+ @target.stub!(:action_name).and_return :bar
0
+ matcher = BeMissing.new
0
+ matcher.matches?(@target)
0
+ matcher.negative_failure_message.should == "expected Foo#bar not to be missing but it was 404"