Changeset 1098
- Timestamp:
- 12/13/07 22:56:41 (1 year ago)
- Files:
-
- trunk/lib/merb/test/rspec.rb (modified) (1 diff)
- trunk/spec/merb/controller_spec.rb (modified) (1 diff)
- trunk/spec/spec_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/merb/test/rspec.rb
r1077 r1098 3 3 module Merb 4 4 module Test 5 module MerbRspecControllerRedirect 6 class BeRedirect 7 def matches?(target) 8 @target = target 9 target == 302 10 end 11 def failure_message 12 "expected to redirect" 13 end 14 def negative_failure_message 15 "expected not to redirect" 16 end 17 end 18 19 class Redirect 20 def matches?(target) 21 @target = target 22 BeRedirect.new.matches?(target.status) 23 end 24 def failure_message 25 "expected #{@target.inspect} to redirect" 26 end 27 def negative_failure_message 28 "expected #{@target.inspect} not to redirect" 29 end 30 end 31 32 class RedirectTo 33 def initialize(expected) 34 @expected = expected 35 end 36 37 def matches?(target) 38 @target = target.headers['Location'] 39 @redirected = BeRedirect.new.matches?(target.status) 40 @target == @expected 41 end 42 43 def failure_message 44 msg = "expected a redirect to <#{@expected}>, but " 45 if @redirected 46 msg << "found one to <#{@target}>" 47 else 48 msg << "there was no redirect" 49 end 50 end 51 52 def negative_failure_message 53 "expected not to redirect to <#{@expected}>, but did anyway" 54 end 55 end 56 57 def be_redirect 58 BeRedirect.new 59 end 60 61 def redirect 62 Redirect.new 63 end 64 65 def redirect_to(expected) 66 RedirectTo.new(expected) 67 end 68 end 69 5 70 module RspecMatchers 6 71 class HaveSelector trunk/spec/merb/controller_spec.rb
r1079 r1098 146 146 # end 147 147 end 148 149 describe "Controller", "redirect spec helpers" do 150 class Redirector < Merb::Controller 151 def index 152 redirect("/foo") 153 end 154 def show 155 end 156 end 157 158 before(:each) do 159 @controller = Redirector.build(fake_request) 160 end 161 162 it "should be able to match redirects" do 163 @controller.dispatch('index') 164 @controller.status.should be_redirect 165 @controller.should redirect 166 @controller.should redirect_to("/foo") 167 end 168 169 it "should be able to negative match redirects" do 170 @controller.dispatch('show') 171 @controller.status.should_not be_redirect 172 @controller.should_not redirect 173 @controller.should_not redirect_to("/foo") 174 end 175 end trunk/spec/spec_helper.rb
r1079 r1098 19 19 config.include(Merb::Test::Helper) 20 20 config.include(Merb::Test::RspecMatchers) 21 config.include(Merb::Test::MerbRspecControllerRedirect) 21 22 end 22 23
