remarkable_rails 3.0.5 → 3.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +20 -3
- data/lib/remarkable_rails/action_controller/macro_stubs.rb +67 -42
- data/lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb +76 -0
- data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +5 -5
- data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +6 -5
- data/locale/en.yml +23 -8
- data/spec/action_controller/macro_stubs_spec.rb +18 -5
- data/spec/action_controller/set_cookies_matcher_spec.rb +150 -0
- data/spec/application/tasks_controller.rb +1 -1
- metadata +6 -4
data/CHANGELOG
CHANGED
@@ -1,6 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
* Added set_cookies matcher [#51]
|
2
|
+
|
3
|
+
* Add a helper to declare that a XmlHttpRequest should be performed:
|
4
|
+
|
5
|
+
describe :get => :show do
|
6
|
+
xhr!
|
7
|
+
|
8
|
+
* Macro stubs now supports blocks too [#50]
|
9
|
+
|
10
|
+
expects :human_attribute_name, :on => Project, :with => :title do |attr|
|
11
|
+
attr.to_s.humanize
|
12
|
+
end
|
13
|
+
|
14
|
+
* :to option in set_session and set_the_flash now accepts Regexp [#46]
|
15
|
+
|
16
|
+
* render_template now works with partials [#43]
|
17
|
+
|
18
|
+
* Added to support for routing example group (inside spec/routing) [#26]
|
19
|
+
|
20
|
+
# v3.0
|
4
21
|
|
5
22
|
[ENHANCEMENT] redirect_to and render_template were ported from rspec-rails to
|
6
23
|
remarkable to provide I18n. The second was also extended to deal with :with,
|
@@ -62,15 +62,20 @@ module Remarkable
|
|
62
62
|
#
|
63
63
|
# You don't have to play with proc all the time. You can call mock_models which
|
64
64
|
# creates a class method that simply returns a proc and a instance method that
|
65
|
-
# do the actual mock.
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
65
|
+
# do the actual mock.
|
66
|
+
#
|
67
|
+
# describe ProjectsController do
|
68
|
+
# mock_models :project
|
69
|
+
#
|
70
|
+
# And it creates:
|
71
|
+
#
|
72
|
+
# def self.mock_project
|
73
|
+
# proc { mock_project }
|
74
|
+
# end
|
70
75
|
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
76
|
+
# def mock_project(stubs={})
|
77
|
+
# @project ||= mock_model(Project, stubs)
|
78
|
+
# end
|
74
79
|
#
|
75
80
|
# Then you can replace those lines:
|
76
81
|
#
|
@@ -84,13 +89,12 @@ module Remarkable
|
|
84
89
|
#
|
85
90
|
# = Give me more!
|
86
91
|
#
|
87
|
-
# If you need to
|
92
|
+
# If you need to set the example group description, you can also call <tt>get</tt>,
|
93
|
+
# <tt>post</tt>, <tt>put</tt> and <tt>delete</tt> methods:
|
88
94
|
#
|
89
95
|
# describe 'my description' do
|
90
96
|
# get :show, :id => 37
|
91
97
|
#
|
92
|
-
# Which is the same as above.
|
93
|
-
#
|
94
98
|
# Things start to get even better when we start to talk about nested resources.
|
95
99
|
# After our ProjectsController is created, we want to create a TasksController:
|
96
100
|
#
|
@@ -112,9 +116,8 @@ module Remarkable
|
|
112
116
|
# As you noticed, you can define parameters that will be available to all requests,
|
113
117
|
# using the method <tt>params</tt>.
|
114
118
|
#
|
115
|
-
# Finally
|
116
|
-
#
|
117
|
-
# run_stubs! and run_action!. Examples:
|
119
|
+
# Finally if you need to write a spec by hand, you can invoke the action and
|
120
|
+
# expectations with run_action!, run_expectations! and run_stubs!. Examples:
|
118
121
|
#
|
119
122
|
# describe :get => :new do
|
120
123
|
# expects :new, :on => Project, :returns => mock_project
|
@@ -127,8 +130,8 @@ module Remarkable
|
|
127
130
|
#
|
128
131
|
# = Performance!
|
129
132
|
#
|
130
|
-
# Remarkable comes with a new way to speed up your tests. It
|
131
|
-
# inside a before(:all), so you can do:
|
133
|
+
# Remarkable comes with a new way to speed up your tests. It performs the
|
134
|
+
# action inside a before(:all), so you can do:
|
132
135
|
#
|
133
136
|
# describe "responding to GET show" do
|
134
137
|
# get! :show, :id => 37
|
@@ -141,17 +144,16 @@ module Remarkable
|
|
141
144
|
#
|
142
145
|
# describe :get! => :show, :id => 37
|
143
146
|
#
|
144
|
-
# The action will be performed just once before
|
145
|
-
#
|
146
|
-
#
|
147
|
-
# be run.
|
147
|
+
# The action will be performed just once before running the macros. If any
|
148
|
+
# error happens while performing the action, rspec will output an error
|
149
|
+
# but ALL the examples inside the example group (describe) won't be run.
|
148
150
|
#
|
149
|
-
# By now, the bang methods works only when integrate_views
|
150
|
-
# when you must
|
151
|
+
# By now, the bang methods works only when integrate_views is true and this
|
152
|
+
# is when you must see a bigger performance gain.
|
151
153
|
#
|
152
|
-
# This comes with some rspec and rspec rails tweakings. So if you want
|
153
|
-
# something before the action is performed (stubs something or log
|
154
|
-
# session), you have to do it giving a block to the action method:
|
154
|
+
# This feature comes with some rspec and rspec rails tweakings. So if you want
|
155
|
+
# to do something before the action is performed (stubs something or log
|
156
|
+
# someone in session), you have to do it giving a block to the action method:
|
155
157
|
#
|
156
158
|
# get! :show, :id => 37 do
|
157
159
|
# login_as(mock_user)
|
@@ -171,13 +173,15 @@ module Remarkable
|
|
171
173
|
def self.included(base) #:nodoc:
|
172
174
|
base.extend ClassMethods
|
173
175
|
base.class_inheritable_reader :expects_chain, :default_action, :default_mime,
|
174
|
-
:default_verb, :default_params, :
|
176
|
+
:default_verb, :default_params, :default_xhr,
|
177
|
+
:before_all_block
|
175
178
|
end
|
176
179
|
|
177
180
|
module ClassMethods
|
178
181
|
|
179
182
|
# Creates a chain that will be evaluated as stub or expectation. The
|
180
|
-
# first parameter is the method expected.
|
183
|
+
# first parameter is the method expected. Also, a block can be given
|
184
|
+
# to calculate the returned value. See examples below.
|
181
185
|
#
|
182
186
|
# == Options
|
183
187
|
#
|
@@ -195,10 +199,14 @@ module Remarkable
|
|
195
199
|
#
|
196
200
|
# == Example
|
197
201
|
#
|
198
|
-
# expects :new, :on => Project, :returns => :mock_project, :times => 2
|
202
|
+
# expects :new, :on => Project, :returns => :mock_project, :times => 2
|
203
|
+
#
|
204
|
+
# expects :human_attribute_name, :on => Project, :with => :title do |attr|
|
205
|
+
# attr.to_s.humanize
|
206
|
+
# end
|
199
207
|
#
|
200
|
-
def expects(*args)
|
201
|
-
write_inheritable_array(:expects_chain, [args])
|
208
|
+
def expects(*args, &block)
|
209
|
+
write_inheritable_array(:expects_chain, [args << block])
|
202
210
|
end
|
203
211
|
|
204
212
|
# The mime type of the request. The value given will be called transformed
|
@@ -227,6 +235,18 @@ module Remarkable
|
|
227
235
|
#
|
228
236
|
def params(params)
|
229
237
|
write_inheritable_hash(:default_params, params)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Sets the request to perform a XmlHttpRequest.
|
241
|
+
#
|
242
|
+
# == Examples
|
243
|
+
#
|
244
|
+
# describe TasksController do
|
245
|
+
# xhr!
|
246
|
+
# end
|
247
|
+
#
|
248
|
+
def xhr!(bool=true)
|
249
|
+
write_inheritable_attribute(:default_xhr, bool)
|
230
250
|
end
|
231
251
|
|
232
252
|
[:get, :post, :put, :delete].each do |verb|
|
@@ -413,7 +433,7 @@ module Remarkable
|
|
413
433
|
def evaluate_expectation_chain(use_expectations=true) #:nodoc:
|
414
434
|
return if self.expects_chain.nil?
|
415
435
|
|
416
|
-
self.expects_chain.each do |method, default_options|
|
436
|
+
self.expects_chain.each do |method, default_options, block|
|
417
437
|
options = default_options.dup
|
418
438
|
|
419
439
|
# Those are used both in expectations and stubs
|
@@ -423,16 +443,18 @@ module Remarkable
|
|
423
443
|
raise ScriptError, "You have to give me :on as an option when calling :expects." if object.nil?
|
424
444
|
|
425
445
|
if use_expectations
|
426
|
-
with = evaluate_value(options.delete(:with))
|
427
|
-
times = options.delete(:times) || 1
|
428
|
-
|
429
446
|
chain = object.should_receive(method)
|
430
|
-
chain = chain.with(with) if with
|
431
|
-
chain = chain.exactly(times).times
|
447
|
+
chain = chain.with(evaluate_value(options.delete(:with))) if options.key?(:with)
|
448
|
+
chain = chain.exactly(options.delete(:times) || 1).times
|
432
449
|
else
|
433
450
|
chain = object.stub!(method)
|
451
|
+
end
|
452
|
+
|
453
|
+
chain = if block
|
454
|
+
chain.and_return(&block)
|
455
|
+
else
|
456
|
+
chain.and_return(return_value)
|
434
457
|
end
|
435
|
-
chain = chain.and_return(return_value)
|
436
458
|
end
|
437
459
|
end
|
438
460
|
|
@@ -456,10 +478,11 @@ module Remarkable
|
|
456
478
|
#
|
457
479
|
# The first parameter is if you want to run expectations or stubs. You
|
458
480
|
# can also supply the verb (get, post, put or delete), which action to
|
459
|
-
# call, parameters
|
460
|
-
# supplied, they override the current
|
481
|
+
# call, parameters, the mime type and if a xhr should be performed. If
|
482
|
+
# any of those parameters are supplied, they override the current
|
483
|
+
# definition.
|
461
484
|
#
|
462
|
-
def run_action!(use_expectations=true, verb=nil, action=nil, params=nil, mime=nil)
|
485
|
+
def run_action!(use_expectations=true, verb=nil, action=nil, params=nil, mime=nil, xhr=nil)
|
463
486
|
return false if controller.send(:performed?)
|
464
487
|
|
465
488
|
evaluate_expectation_chain(use_expectations)
|
@@ -467,11 +490,13 @@ module Remarkable
|
|
467
490
|
mime ||= default_mime
|
468
491
|
verb ||= default_verb
|
469
492
|
action ||= default_action
|
470
|
-
params ||= default_params
|
493
|
+
params ||= default_params
|
494
|
+
xhr ||= default_xhr
|
471
495
|
|
472
496
|
raise ScriptError, "No action was performed or declared." unless verb && action
|
473
497
|
|
474
|
-
request.env["HTTP_ACCEPT"] ||= mime.to_s
|
498
|
+
request.env["HTTP_ACCEPT"] ||= mime.to_s if mime
|
499
|
+
request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' if xhr
|
475
500
|
send(verb, action, params)
|
476
501
|
end
|
477
502
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'set_cookies_matcher')
|
2
|
+
|
3
|
+
module Remarkable
|
4
|
+
module ActionController
|
5
|
+
module Matchers
|
6
|
+
class SetCookiesMatcher < SetSessionMatcher #:nodoc:
|
7
|
+
|
8
|
+
# For cookies to work properly, we have:
|
9
|
+
#
|
10
|
+
# On Rails 2.1.2 and 2.2.2:
|
11
|
+
#
|
12
|
+
# 1. Wrap :to values in an array;
|
13
|
+
# 2. When :to is false or nil, make it be an empty array;
|
14
|
+
# 3. Convert all keys to string.
|
15
|
+
#
|
16
|
+
# On Rails 2.3.2:
|
17
|
+
#
|
18
|
+
# 1. Convert :to values to string, unless it's nil
|
19
|
+
# 2. Convert all keys to string.
|
20
|
+
#
|
21
|
+
before_assert do
|
22
|
+
if @subject.request.env.key?("rack.input")
|
23
|
+
@options[:to] = @options[:to].to_s if @options.key?(:to) && !@options[:to].nil?
|
24
|
+
else
|
25
|
+
@options[:to] = @options[:to] ? [@options[:to]] : [] if @options.key?(:to)
|
26
|
+
end
|
27
|
+
|
28
|
+
@keys.collect!(&:to_s)
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def session
|
33
|
+
@subject ? (@subject.response.cookies || {}) : {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def interpolation_options
|
37
|
+
{ :cookies_inspect => session.symbolize_keys!.inspect }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
# Ensures that the given cookie keys were set. If you want to check that
|
43
|
+
# a cookie is not being set, just do:
|
44
|
+
#
|
45
|
+
# should_not_set_cookies :user
|
46
|
+
#
|
47
|
+
# If you want to assure that a cookie is being set to nil, do instead:
|
48
|
+
#
|
49
|
+
# should_set_cookies :user, :to => nil
|
50
|
+
#
|
51
|
+
# Note: this method is also aliased as <tt>set_cookie</tt>.
|
52
|
+
#
|
53
|
+
# == Options
|
54
|
+
#
|
55
|
+
# * <tt>:to</tt> - The value to compare the session key.
|
56
|
+
# It accepts procs and be also given as a block (see examples below).
|
57
|
+
#
|
58
|
+
# == Examples
|
59
|
+
#
|
60
|
+
# should_set_cookies :user_id, :user
|
61
|
+
# should_set_cookies :user_id, :to => 2
|
62
|
+
# should_set_cookies :user, :to => proc{ users(:first) }
|
63
|
+
# should_set_cookies(:user){ users(:first) }
|
64
|
+
#
|
65
|
+
# it { should set_cookies(:user_id, :user) }
|
66
|
+
# it { should set_cookies(:user_id, :to => 2) }
|
67
|
+
# it { should set_cookies(:user, :to => users(:first)) }
|
68
|
+
#
|
69
|
+
def set_cookies(*args, &block)
|
70
|
+
SetCookiesMatcher.new(*args, &block).spec(self)
|
71
|
+
end
|
72
|
+
alias :set_cookie :set_cookies
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -34,7 +34,7 @@ module Remarkable
|
|
34
34
|
assert_contains(session.values, @options[:to])
|
35
35
|
end
|
36
36
|
|
37
|
-
def assigned_value?
|
37
|
+
def assigned_value?
|
38
38
|
session.key?(@key)
|
39
39
|
end
|
40
40
|
|
@@ -74,14 +74,14 @@ module Remarkable
|
|
74
74
|
|
75
75
|
end
|
76
76
|
|
77
|
-
# Ensures that
|
78
|
-
# is not being set,
|
77
|
+
# Ensures that the given session keys were set. If you want to check that
|
78
|
+
# a variable is not being set, just do:
|
79
79
|
#
|
80
|
-
# should_not_set_session
|
80
|
+
# should_not_set_session :user
|
81
81
|
#
|
82
82
|
# If you want to assure that a variable is being set to nil, do instead:
|
83
83
|
#
|
84
|
-
# should_set_session
|
84
|
+
# should_set_session :user, :to => nil
|
85
85
|
#
|
86
86
|
# == Options
|
87
87
|
#
|
@@ -16,18 +16,19 @@ module Remarkable
|
|
16
16
|
|
17
17
|
end
|
18
18
|
|
19
|
-
# Ensures that a
|
20
|
-
# is not being set,
|
19
|
+
# Ensures that a flash message is being set. If you want to check that a
|
20
|
+
# flash is not being set, just do:
|
21
21
|
#
|
22
|
-
# should_not_set_the_flash
|
22
|
+
# should_not_set_the_flash :user
|
23
23
|
#
|
24
24
|
# If you want to assure that a flash is being set to nil, do instead:
|
25
25
|
#
|
26
|
-
# should_set_the_flash
|
26
|
+
# should_set_the_flash :user, :to => nil
|
27
27
|
#
|
28
28
|
# == Options
|
29
29
|
#
|
30
|
-
# * <tt>:to</tt> - The value to compare the flash key.
|
30
|
+
# * <tt>:to</tt> - The value to compare the flash key.
|
31
|
+
# It accepts procs and can also be given as a block (see examples below)
|
31
32
|
#
|
32
33
|
# == Examples
|
33
34
|
#
|
data/locale/en.yml
CHANGED
@@ -2,7 +2,7 @@ en:
|
|
2
2
|
remarkable:
|
3
3
|
action_controller:
|
4
4
|
responding: "responding to #{{verb}} {{action}}"
|
5
|
-
mime_type: "with {{format}}"
|
5
|
+
mime_type: "with {{format}}"
|
6
6
|
|
7
7
|
assign_to:
|
8
8
|
description: "assign {{names}}"
|
@@ -12,13 +12,13 @@ en:
|
|
12
12
|
is_equal_value: "assign {{name}} to be equal to {{with}}, got {{assign_inspect}}"
|
13
13
|
optionals:
|
14
14
|
with_kind_of:
|
15
|
-
positive: "with kind of {{value}}"
|
15
|
+
positive: "with kind of {{value}}"
|
16
16
|
|
17
17
|
filter_params:
|
18
18
|
description: "filter {{params}} parameters from log"
|
19
19
|
expectations:
|
20
20
|
respond_to_filter_params: "controller to respond to filter_parameters (controller is not filtering any parameter)"
|
21
|
-
is_filtered: "{{param}} to be filtered, got no filtering"
|
21
|
+
is_filtered: "{{param}} to be filtered, got no filtering"
|
22
22
|
|
23
23
|
redirect_to:
|
24
24
|
description: "redirect to {{expected}}"
|
@@ -28,7 +28,7 @@ en:
|
|
28
28
|
url_matches: "redirect to {{expected}}, got redirect to {{actual}}"
|
29
29
|
optionals:
|
30
30
|
with:
|
31
|
-
positive: "with status {{inspect}}"
|
31
|
+
positive: "with status {{inspect}}"
|
32
32
|
|
33
33
|
render_template:
|
34
34
|
description: "render"
|
@@ -50,7 +50,7 @@ en:
|
|
50
50
|
body:
|
51
51
|
positive: "with body {{inspect}}"
|
52
52
|
content_type:
|
53
|
-
positive: "with content type {{inspect}}"
|
53
|
+
positive: "with content type {{inspect}}"
|
54
54
|
|
55
55
|
respond_with:
|
56
56
|
description: "respond"
|
@@ -64,13 +64,25 @@ en:
|
|
64
64
|
body:
|
65
65
|
positive: "with body {{inspect}}"
|
66
66
|
content_type:
|
67
|
-
positive: "with content type {{inspect}}"
|
67
|
+
positive: "with content type {{inspect}}"
|
68
68
|
|
69
69
|
route:
|
70
70
|
description: "route {{method}} {{path}} to/from {{options}}"
|
71
71
|
expectations:
|
72
72
|
map_to_path: "to map {{options}} to {{method}} {{path}}, got {{actual}}"
|
73
|
-
generate_params: "to generate params {{options}} from {{method}} {{path}}, got {{actual}}"
|
73
|
+
generate_params: "to generate params {{options}} from {{method}} {{path}}, got {{actual}}"
|
74
|
+
|
75
|
+
set_cookies:
|
76
|
+
description: "set cookies {{keys}}"
|
77
|
+
expectations:
|
78
|
+
is_not_empty: "any cookie to be set, got {{cookies_inspect}}"
|
79
|
+
contains_value: "any cookie to be set to {{to}}, got {{cookies_inspect}}"
|
80
|
+
assigned_value: "cookie {{key}} to be set, got {{cookies_inspect}}"
|
81
|
+
is_equal_value: "cookie {{key}} to be set to {{to}}, got {{cookies_inspect}}"
|
82
|
+
optionals:
|
83
|
+
to:
|
84
|
+
positive: "to {{inspect}}"
|
85
|
+
negative: "to {{inspect}}"
|
74
86
|
|
75
87
|
set_session:
|
76
88
|
description: "set session variable {{keys}}"
|
@@ -82,6 +94,7 @@ en:
|
|
82
94
|
optionals:
|
83
95
|
to:
|
84
96
|
positive: "to {{inspect}}"
|
97
|
+
negative: "to {{inspect}}"
|
85
98
|
|
86
99
|
set_the_flash:
|
87
100
|
description: "set the flash message {{keys}}"
|
@@ -92,4 +105,6 @@ en:
|
|
92
105
|
is_equal_value: "flash message {{key}} to be set to {{to}}, got {{flash_inspect}}"
|
93
106
|
optionals:
|
94
107
|
to:
|
95
|
-
positive: "to {{inspect}}"
|
108
|
+
positive: "to {{inspect}}"
|
109
|
+
negative: "to {{inspect}}"
|
110
|
+
|
@@ -154,10 +154,18 @@ describe 'MacroStubs' do
|
|
154
154
|
|
155
155
|
[:delete, :delete!].each do |method|
|
156
156
|
|
157
|
-
describe method => :destroy, :id => 37 do
|
158
|
-
expects :find, :on => Task,
|
159
|
-
expects :destroy, :on => mock_task
|
160
|
-
|
157
|
+
describe method => :destroy, :id => '37' do
|
158
|
+
expects :find, :on => Task, :with => '37', :returns => mock_task
|
159
|
+
expects :destroy, :on => mock_task
|
160
|
+
expects :title, :on => mock_task, :with => false do |boolean|
|
161
|
+
if boolean
|
162
|
+
'This should not appear'
|
163
|
+
else
|
164
|
+
'My favourite task'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
xhr!
|
161
169
|
subject { controller }
|
162
170
|
|
163
171
|
should_assign_to :task
|
@@ -166,7 +174,7 @@ describe 'MacroStubs' do
|
|
166
174
|
|
167
175
|
should_set_the_flash
|
168
176
|
should_set_the_flash :notice
|
169
|
-
should_set_the_flash :notice, :to =>
|
177
|
+
should_set_the_flash :notice, :to => %{"My favourite task" was removed}
|
170
178
|
|
171
179
|
should_set_session
|
172
180
|
should_set_session :last_task_id
|
@@ -187,6 +195,11 @@ describe 'MacroStubs' do
|
|
187
195
|
|
188
196
|
it 'should provide a description based on parameters given in describe' do
|
189
197
|
self.class.description.should =~ /responding to #DELETE destroy$/
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should perform a XmlHttpRequest' do
|
201
|
+
run_action!
|
202
|
+
request.env['HTTP_X_REQUESTED_WITH'].should == 'XMLHttpRequest'
|
190
203
|
end
|
191
204
|
end
|
192
205
|
|
@@ -0,0 +1,150 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe 'set_cookies' do
|
4
|
+
include FunctionalBuilder
|
5
|
+
|
6
|
+
describe 'messages' do
|
7
|
+
before(:each) do
|
8
|
+
@matcher = set_cookies(:user).to(1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should contain a description message' do
|
12
|
+
@matcher = set_cookies(:user)
|
13
|
+
@matcher.description.should == 'set cookies user'
|
14
|
+
|
15
|
+
@matcher.to(1)
|
16
|
+
@matcher.description.should == 'set cookies user to 1'
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should set is_not_empty? message' do
|
20
|
+
build_response
|
21
|
+
@matcher = set_cookies
|
22
|
+
@matcher.matches?(@controller)
|
23
|
+
@matcher.failure_message.should == 'Expected any cookie to be set, got {}'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set assigned_value? message' do
|
27
|
+
build_response
|
28
|
+
@matcher = set_cookies(:user)
|
29
|
+
@matcher.matches?(@controller)
|
30
|
+
@matcher.failure_message.should == 'Expected cookie user to be set, got {}'
|
31
|
+
end
|
32
|
+
|
33
|
+
if RAILS_VERSION =~ /^2.1/ || RAILS_VERSION =~ /^2.2/
|
34
|
+
it 'should set contains_value? message' do
|
35
|
+
build_response { cookies[:user] = 10 }
|
36
|
+
@matcher = set_cookies.to(1)
|
37
|
+
@matcher.matches?(@controller)
|
38
|
+
@matcher.failure_message.should == 'Expected any cookie to be set to [1], got {:user=>[10]}'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should set is_equal_value? message' do
|
42
|
+
build_response { cookies[:user] = 2 }
|
43
|
+
@matcher.matches?(@controller)
|
44
|
+
@matcher.failure_message.should == 'Expected cookie user to be set to [1], got {:user=>[2]}'
|
45
|
+
end
|
46
|
+
else
|
47
|
+
it 'should set contains_value? message' do
|
48
|
+
build_response { cookies[:user] = 10 }
|
49
|
+
@matcher = set_cookies.to(1)
|
50
|
+
@matcher.matches?(@controller)
|
51
|
+
@matcher.failure_message.should == 'Expected any cookie to be set to "1", got {:user=>"10"}'
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should set is_equal_value? message' do
|
55
|
+
build_response { cookies[:user] = 2 }
|
56
|
+
@matcher.matches?(@controller)
|
57
|
+
@matcher.failure_message.should == 'Expected cookie user to be set to "1", got {:user=>"2"}'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'matcher' do
|
63
|
+
before(:each) do
|
64
|
+
build_response {
|
65
|
+
cookies[:user] = 'jose'
|
66
|
+
cookies[:address] = 'Avenue'
|
67
|
+
cookies[:true] = true
|
68
|
+
cookies[:false] = false
|
69
|
+
cookies[:nil] = nil
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
it { should set_cookies }
|
74
|
+
it { should set_cookies.to('jose') }
|
75
|
+
it { should set_cookies(:user) }
|
76
|
+
it { should set_cookies(:user).to('jose') }
|
77
|
+
|
78
|
+
it { should_not set_cookies.to('joseph') }
|
79
|
+
it { should_not set_cookies(:post) }
|
80
|
+
it { should_not set_cookies(:user).to('joseph') }
|
81
|
+
|
82
|
+
it { should set_cookies(:user){ 'jose' } }
|
83
|
+
it { should set_cookies(:user, :to => proc{ 'jose' }) }
|
84
|
+
|
85
|
+
it { should_not set_cookies(:user).to(nil) }
|
86
|
+
it { should_not set_cookies(:user){ 'joseph' } }
|
87
|
+
it { should_not set_cookies(:user, :to => proc{ 'joseph' }) }
|
88
|
+
|
89
|
+
it { should set_cookies(:true) }
|
90
|
+
it { should set_cookies(:true).to(true) }
|
91
|
+
it { should_not set_cookies(:true).to(false) }
|
92
|
+
|
93
|
+
it { should set_cookies(:false) }
|
94
|
+
it { should set_cookies(:false).to(false) }
|
95
|
+
it { should_not set_cookies(:false).to(true) }
|
96
|
+
|
97
|
+
it { should set_cookies(:nil) }
|
98
|
+
it { should set_cookies(:nil).to(nil) }
|
99
|
+
it { should_not set_cookies(:nil).to(true) }
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'macro' do
|
103
|
+
before(:each) do
|
104
|
+
build_response {
|
105
|
+
cookies[:user] = 'jose'
|
106
|
+
cookies[:address] = 'Avenue'
|
107
|
+
cookies[:true] = true
|
108
|
+
cookies[:false] = false
|
109
|
+
cookies[:nil] = nil
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
should_set_cookies
|
114
|
+
should_set_cookies :to => 'jose'
|
115
|
+
should_set_cookies :user
|
116
|
+
should_set_cookies :user, :to => 'jose'
|
117
|
+
|
118
|
+
should_not_set_cookies :to => 'joseph'
|
119
|
+
should_not_set_cookies :post
|
120
|
+
should_not_set_cookies :user, :to => 'joseph'
|
121
|
+
|
122
|
+
should_set_cookies(:user){ 'jose' }
|
123
|
+
should_set_cookies :user, :to => proc{ 'jose' }
|
124
|
+
|
125
|
+
should_not_set_cookies :user, :to => nil
|
126
|
+
should_not_set_cookies(:user){ 'joseph' }
|
127
|
+
should_not_set_cookies :user, :to => proc{ 'joseph' }
|
128
|
+
|
129
|
+
should_set_cookies :true
|
130
|
+
should_set_cookies :true, :to => true
|
131
|
+
should_not_set_cookies :true, :to => false
|
132
|
+
|
133
|
+
should_set_cookies :false
|
134
|
+
should_set_cookies :false, :to => false
|
135
|
+
should_not_set_cookies :false, :to => true
|
136
|
+
|
137
|
+
should_set_cookies :nil
|
138
|
+
should_set_cookies :nil, :to => nil
|
139
|
+
should_not_set_cookies :nil, :to => true
|
140
|
+
end
|
141
|
+
|
142
|
+
describe 'with no parameter' do
|
143
|
+
before(:each) { build_response }
|
144
|
+
|
145
|
+
should_not_set_cookies
|
146
|
+
it { should_not set_cookies }
|
147
|
+
end
|
148
|
+
|
149
|
+
generate_macro_stubs_specs_for(:set_cookies)
|
150
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: remarkable_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Brando
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-04-
|
13
|
+
date: 2009-04-22 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 3.0.
|
34
|
+
version: 3.0.6
|
35
35
|
version:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: remarkable_activerecord
|
@@ -41,7 +41,7 @@ dependencies:
|
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: 3.0.
|
44
|
+
version: 3.0.6
|
45
45
|
version:
|
46
46
|
description: "Remarkable Rails: collection of matchers and macros with I18n for Rails"
|
47
47
|
email:
|
@@ -74,6 +74,7 @@ files:
|
|
74
74
|
- lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb
|
75
75
|
- lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb
|
76
76
|
- lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb
|
77
|
+
- lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb
|
77
78
|
- lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb
|
78
79
|
- lib/remarkable_rails/action_view.rb
|
79
80
|
- lib/remarkable_rails/action_controller.rb
|
@@ -121,6 +122,7 @@ test_files:
|
|
121
122
|
- spec/action_controller
|
122
123
|
- spec/action_controller/macro_stubs_spec.rb
|
123
124
|
- spec/action_controller/assign_to_matcher_spec.rb
|
125
|
+
- spec/action_controller/set_cookies_matcher_spec.rb
|
124
126
|
- spec/action_controller/set_session_matcher_spec.rb
|
125
127
|
- spec/action_controller/redirect_to_matcher_spec.rb
|
126
128
|
- spec/action_controller/route_matcher_spec.rb
|