GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Added Provide matcher class, so you can do "controller.should provide( 
:xml )" in your specs.

Signed-off-by: Michael S. Klishin <michael@novemberain.com>
wzph (author)
Sat Apr 19 15:35:28 -0700 2008
michaelklishin (committer)
Thu May 01 23:33:04 -0700 2008
commit  0c958e38d916a1f829306dc4aebf72d753a9f838
tree    e65a96b029a7257d073ecc5e2fd8a33d39261dc0
parent  76a666372cdf1d59ac1699b289b981cef3475dab
...
158
159
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
162
163
...
266
267
268
269
270
 
 
 
 
 
 
 
 
 
 
...
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
...
304
305
306
 
307
308
309
310
311
312
313
314
315
316
317
0
@@ -158,6 +158,44 @@ module Merb::Test::Rspec::ControllerMatchers
0
     end
0
   end
0
 
0
+ class Provide
0
+
0
+ # === Parameters
0
+ # Symbol:: A format to check
0
+ def initialize(expected)
0
+ @expected = expected
0
+ end
0
+
0
+ # ==== Parameters
0
+ # target<Symbol>::
0
+ # A format (e.g., :html, :json, etc.)
0
+ #
0
+ # ==== Returns
0
+ # Boolean:: True if the provided formats include the target
0
+ def matches?(target)
0
+ @target = target
0
+ provided_formats.include?( target )
0
+ end
0
+
0
+ # ==== Returns
0
+ # String:: The failure message.
0
+ def failure_message
0
+ "expected #{@target.name} to provide #{@expected}, but it doesn't"
0
+ end
0
+
0
+ # ==== Returns
0
+ # String:: The failure message to be displayed in negative matches.
0
+ def negative_failure_message
0
+ "expected #{@target.name} not to provide #{@expected}, but it does"
0
+ end
0
+
0
+ # ==== Returns
0
+ # Array[Symbol]:: The formats the expected provides
0
+ def provided_formats
0
+ @expected.class_provided_formats
0
+ end
0
+ end
0
+
0
   # Passes if the target was redirected, or the target is a redirection (300
0
   # level) response code.
0
   #
0
@@ -266,4 +304,13 @@ module Merb::Test::Rspec::ControllerMatchers
0
   end
0
 
0
   alias_method :be_client_error, :be_missing
0
-end
0
\ No newline at end of file
0
+
0
+ # Passes if the controller actually provides the target format
0
+ #
0
+ # ==== Examples
0
+ # ControllerClass.should provide( :html )
0
+ # controller_instance.should provide( :xml )
0
+ def provide( expected )
0
+ Provide.new( expected )
0
+ end
0
+end
...
374
375
376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
378
379
 
...
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
 
402
403
0
@@ -374,5 +374,29 @@ module Merb::Test::Rspec
0
         end
0
       end
0
     end
0
+
0
+ describe Provide do
0
+ class TestController < Merb::Controller
0
+ provides :xml
0
+ end
0
+
0
+ it 'should match for formats a controller class provides' do
0
+ Provide.new( TestController ).matches?( :xml ).should be_true
0
+ end
0
+
0
+ it 'should match for formats a controller instance provides' do
0
+ t = TestController.new( fake_request )
0
+ Provide.new( t ).matches?( :xml ).should be_true
0
+ end
0
+
0
+ it 'should not match for formats a controller class does not provide' do
0
+ Provide.new( TestController ).matches?( :yaml ).should be_false
0
+ end
0
+
0
+ it 'should not match for formats a controller instance does not provide' do
0
+ t = TestController.new( fake_request )
0
+ Provide.new( t ).matches?( :yaml ).should be_false
0
+ end
0
+ end
0
   end
0
-end
0
\ No newline at end of file
0
+end

Comments

    No one has commented yet.