remarkable_rails 3.1.8 → 3.1.9
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 +91 -88
- data/LICENSE +20 -20
- data/README +80 -80
- data/lib/remarkable_rails/action_controller/base.rb +29 -29
- data/lib/remarkable_rails/action_controller/macro_stubs.rb +459 -457
- data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +92 -92
- data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +41 -41
- data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +119 -119
- data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +146 -146
- data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +126 -126
- data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +135 -109
- data/lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb +49 -49
- data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +106 -106
- data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +54 -54
- data/lib/remarkable_rails/action_controller.rb +22 -22
- data/lib/remarkable_rails/action_view/base.rb +7 -7
- data/lib/remarkable_rails/action_view.rb +18 -18
- data/lib/remarkable_rails/active_orm.rb +19 -19
- data/lib/remarkable_rails.rb +30 -30
- data/locale/en.yml +110 -110
- data/spec/action_controller/assign_to_matcher_spec.rb +142 -142
- data/spec/action_controller/filter_params_matcher_spec.rb +64 -64
- data/spec/action_controller/macro_stubs_spec.rb +234 -208
- data/spec/action_controller/redirect_to_matcher_spec.rb +102 -102
- data/spec/action_controller/render_template_matcher_spec.rb +251 -251
- data/spec/action_controller/respond_with_matcher_spec.rb +223 -223
- data/spec/action_controller/route_matcher_spec.rb +96 -79
- data/spec/action_controller/set_cookies_matcher_spec.rb +149 -149
- data/spec/action_controller/set_session_matcher_spec.rb +141 -141
- data/spec/action_controller/set_the_flash_matcher_spec.rb +93 -93
- data/spec/application/application.rb +15 -15
- data/spec/application/tasks_controller.rb +34 -34
- data/spec/functional_builder.rb +88 -88
- data/spec/rcov.opts +2 -2
- data/spec/remarkable_rails_spec.rb +5 -5
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +42 -42
- metadata +7 -7
@@ -1,54 +1,54 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
# Define a metaclass in the Object because we are going to need it.
|
4
|
-
class Object; def metaclass; class << self; self; end; end; end
|
5
|
-
|
6
|
-
describe 'MacroStubs' do
|
7
|
-
controller_name 'tasks'
|
8
|
-
mock_models :task
|
9
|
-
|
10
|
-
def current_id; '37'; end
|
11
|
-
|
12
|
-
describe 'mock_models' do
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
# Define a metaclass in the Object because we are going to need it.
|
4
|
+
class Object; def metaclass; class << self; self; end; end; end
|
5
|
+
|
6
|
+
describe 'MacroStubs' do
|
7
|
+
controller_name 'tasks'
|
8
|
+
mock_models :task
|
9
|
+
|
10
|
+
def current_id; '37'; end
|
11
|
+
|
12
|
+
describe 'mock_models' do
|
13
13
|
before(:each) do
|
14
|
-
self.class.metaclass.send(:undef_method, :projects_proc) if self.class.respond_to?(:projects_proc)
|
15
|
-
self.class.metaclass.send(:undef_method, :project_proc) if self.class.respond_to?(:project_proc)
|
16
|
-
self.class.send(:undef_method, :mock_project) if self.respond_to?(:mock_project)
|
17
|
-
end
|
14
|
+
self.class.metaclass.send(:undef_method, :projects_proc) if self.class.respond_to?(:projects_proc)
|
15
|
+
self.class.metaclass.send(:undef_method, :project_proc) if self.class.respond_to?(:project_proc)
|
16
|
+
self.class.send(:undef_method, :mock_project) if self.respond_to?(:mock_project)
|
17
|
+
end
|
18
18
|
|
19
19
|
it 'should alias model_proc to mock_model' do
|
20
20
|
self.class.respond_to?(:mock_project).should be_false
|
21
|
-
self.class.respond_to?(:mock_projects).should be_false
|
22
|
-
self.class.mock_models :project
|
21
|
+
self.class.respond_to?(:mock_projects).should be_false
|
22
|
+
self.class.mock_models :project
|
23
23
|
self.class.respond_to?(:mock_project).should be_true
|
24
24
|
self.class.respond_to?(:mock_projects).should be_true
|
25
25
|
end
|
26
|
-
|
27
|
-
it 'should create a class singular proc method' do
|
28
|
-
self.class.respond_to?(:project_proc).should be_false
|
29
|
-
self.class.mock_models :project
|
30
|
-
self.class.respond_to?(:project_proc).should be_true
|
26
|
+
|
27
|
+
it 'should create a class singular proc method' do
|
28
|
+
self.class.respond_to?(:project_proc).should be_false
|
29
|
+
self.class.mock_models :project
|
30
|
+
self.class.respond_to?(:project_proc).should be_true
|
31
31
|
end
|
32
32
|
|
33
|
-
it 'should create a class plural proc method' do
|
34
|
-
self.class.respond_to?(:projects_proc).should be_false
|
35
|
-
self.class.mock_models :project
|
36
|
-
self.class.respond_to?(:projects_proc).should be_true
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'should create an instance mock method' do
|
40
|
-
self.respond_to?(:mock_project).should be_false
|
41
|
-
self.class.mock_models :project
|
42
|
-
self.respond_to?(:mock_project).should be_true
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should create just an instance method when :class_method is false' do
|
46
|
-
self.class.respond_to?(:project_proc).should be_false
|
47
|
-
self.respond_to?(:mock_project).should be_false
|
48
|
-
self.class.mock_models :project, :class_method => false
|
49
|
-
self.class.respond_to?(:project_proc).should be_false
|
50
|
-
self.respond_to?(:mock_project).should be_true
|
51
|
-
end
|
33
|
+
it 'should create a class plural proc method' do
|
34
|
+
self.class.respond_to?(:projects_proc).should be_false
|
35
|
+
self.class.mock_models :project
|
36
|
+
self.class.respond_to?(:projects_proc).should be_true
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should create an instance mock method' do
|
40
|
+
self.respond_to?(:mock_project).should be_false
|
41
|
+
self.class.mock_models :project
|
42
|
+
self.respond_to?(:mock_project).should be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should create just an instance method when :class_method is false' do
|
46
|
+
self.class.respond_to?(:project_proc).should be_false
|
47
|
+
self.respond_to?(:mock_project).should be_false
|
48
|
+
self.class.mock_models :project, :class_method => false
|
49
|
+
self.class.respond_to?(:project_proc).should be_false
|
50
|
+
self.respond_to?(:mock_project).should be_true
|
51
|
+
end
|
52
52
|
|
53
53
|
it 'should allow the mock class to be set' do
|
54
54
|
self.class.mock_model :project, :as => "::Admin::Project"
|
@@ -56,24 +56,24 @@ describe 'MacroStubs' do
|
|
56
56
|
mock_project
|
57
57
|
}.should raise_error(NameError, "uninitialized constant Admin")
|
58
58
|
end
|
59
|
-
|
60
|
-
it 'should create procs which evals to a mock' do
|
61
|
-
proc = self.class.task_proc
|
62
|
-
proc.should be_kind_of(Proc)
|
63
|
-
|
64
|
-
@task.should be_nil
|
65
|
-
instance_eval(&proc).should == mock_task
|
66
|
-
@task.should_not be_nil
|
59
|
+
|
60
|
+
it 'should create procs which evals to a mock' do
|
61
|
+
proc = self.class.task_proc
|
62
|
+
proc.should be_kind_of(Proc)
|
63
|
+
|
64
|
+
@task.should be_nil
|
65
|
+
instance_eval(&proc).should == mock_task
|
66
|
+
@task.should_not be_nil
|
67
67
|
end
|
68
68
|
|
69
|
-
it 'should create procs which evals to an array of mocks' do
|
70
|
-
proc = self.class.tasks_proc
|
71
|
-
proc.should be_kind_of(Proc)
|
72
|
-
|
73
|
-
@task.should be_nil
|
69
|
+
it 'should create procs which evals to an array of mocks' do
|
70
|
+
proc = self.class.tasks_proc
|
71
|
+
proc.should be_kind_of(Proc)
|
72
|
+
|
73
|
+
@task.should be_nil
|
74
74
|
instance_eval(&proc).should == [ mock_task ]
|
75
|
-
@task.should == mock_task
|
76
|
-
end
|
75
|
+
@task.should == mock_task
|
76
|
+
end
|
77
77
|
end
|
78
78
|
|
79
79
|
describe 'failures' do
|
@@ -121,126 +121,152 @@ describe 'MacroStubs' do
|
|
121
121
|
after(:each) do
|
122
122
|
teardown_mocks_for_rspec
|
123
123
|
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe '
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'with array in options' do
|
127
|
+
expects :find, :on => Task, :with => [proc{ current_id }, 1], :returns => [proc{ current_id }, 2]
|
128
|
+
|
129
|
+
it 'should evaluate all procs in :with option' do
|
130
|
+
run_expectations!
|
131
|
+
|
132
|
+
lambda {
|
133
|
+
Task.find(1)
|
134
|
+
}.should raise_error(Spec::Mocks::MockExpectationError, /expected :find with \("37"\, 1\) but received it with \(1\)/)
|
135
|
+
|
136
|
+
lambda {
|
137
|
+
Task.find("37", 1)
|
138
|
+
}.should_not raise_error
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should evaluate all procs in :returns option' do
|
142
|
+
run_expectations!
|
143
|
+
|
144
|
+
Task.find("37", 1).should eql(["37", 2])
|
145
|
+
end
|
146
|
+
|
147
|
+
after(:each) do
|
148
|
+
teardown_mocks_for_rspec
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe 'when extending describe group behavior' do
|
127
153
|
expects :find, :on => Task, :with => proc{ current_id }, :returns => task_proc
|
128
|
-
expects :count, :max, :min, :on => Task
|
129
|
-
|
130
|
-
get :show, :id => 37
|
131
|
-
params :special_task_id => 42
|
132
|
-
mime Mime::HTML
|
133
|
-
|
134
|
-
it 'should run action declared in a class method' do
|
135
|
-
@controller.send(:performed?).should_not be_true
|
136
|
-
|
137
|
-
run_action!(false)
|
138
|
-
|
139
|
-
@controller.action_name.should == 'show'
|
140
|
-
@controller.request.method.should == :get
|
141
|
-
@controller.send(:performed?).should be_true
|
142
|
-
end
|
154
|
+
expects :count, :max, :min, :on => Task
|
155
|
+
|
156
|
+
get :show, :id => 37
|
157
|
+
params :special_task_id => 42
|
158
|
+
mime Mime::HTML
|
159
|
+
|
160
|
+
it 'should run action declared in a class method' do
|
161
|
+
@controller.send(:performed?).should_not be_true
|
162
|
+
|
163
|
+
run_action!(false)
|
164
|
+
|
165
|
+
@controller.action_name.should == 'show'
|
166
|
+
@controller.request.method.should == :get
|
167
|
+
@controller.send(:performed?).should be_true
|
168
|
+
end
|
143
169
|
|
144
170
|
it 'should raise an error if an invalid key is supplied' do
|
145
171
|
lambda {
|
146
172
|
self.class.expects :find, :on => Task, :and_return => true
|
147
173
|
}.should raise_error(ArgumentError, "Unknown key(s): and_return")
|
148
174
|
end
|
149
|
-
|
150
|
-
it 'should use parameters given in params on request' do
|
151
|
-
self.should_receive(:current_id).once.and_return('37')
|
152
|
-
run_action!
|
153
|
-
@request.parameters[:special_task_id].should == '42'
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'should respond with the supplied mime type' do
|
157
|
-
self.should_receive(:current_id).once.and_return('37')
|
158
|
-
run_action!
|
159
|
-
@response.content_type.should == Mime::HTML.to_s
|
160
|
-
end
|
161
|
-
|
162
|
-
it 'should run action with expectations' do
|
163
|
-
self.should_receive(:current_id).once.and_return('37')
|
164
|
-
run_action!
|
165
|
-
@controller.send(:performed?).should be_true
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'should not run action twice' do
|
169
|
-
run_action!
|
170
|
-
@controller.send(:performed?).should be_true
|
171
|
-
proc{ run_action!.should be_false }.should_not raise_error
|
172
|
-
end
|
173
|
-
|
174
|
-
it 'should run expectations without performing an action' do
|
175
|
-
self.should_receive(:current_id).once.and_return('37')
|
176
|
-
run_expectations!
|
175
|
+
|
176
|
+
it 'should use parameters given in params on request' do
|
177
|
+
self.should_receive(:current_id).once.and_return('37')
|
178
|
+
run_action!
|
179
|
+
@request.parameters[:special_task_id].should == '42'
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'should respond with the supplied mime type' do
|
183
|
+
self.should_receive(:current_id).once.and_return('37')
|
184
|
+
run_action!
|
185
|
+
@response.content_type.should == Mime::HTML.to_s
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should run action with expectations' do
|
189
|
+
self.should_receive(:current_id).once.and_return('37')
|
190
|
+
run_action!
|
191
|
+
@controller.send(:performed?).should be_true
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'should not run action twice' do
|
195
|
+
run_action!
|
196
|
+
@controller.send(:performed?).should be_true
|
197
|
+
proc{ run_action!.should be_false }.should_not raise_error
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should run expectations without performing an action' do
|
201
|
+
self.should_receive(:current_id).once.and_return('37')
|
202
|
+
run_expectations!
|
177
203
|
@controller.send(:performed?).should_not be_true
|
178
|
-
get :show, :id => '37' # Execute the action to match expectations
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'should run action with stubs' do
|
182
|
-
self.should_receive(:current_id).never
|
183
|
-
run_action!(false)
|
184
|
-
@controller.send(:performed?).should be_true
|
185
|
-
end
|
186
|
-
|
187
|
-
it 'should run stubs without performing an action' do
|
188
|
-
self.should_receive(:current_id).never
|
189
|
-
run_stubs!
|
190
|
-
@controller.send(:performed?).should_not be_true
|
191
|
-
end
|
192
|
-
|
193
|
-
describe Mime::XML do
|
194
|
-
expects :to_xml, :on => task_proc, :returns => 'XML'
|
195
|
-
|
196
|
-
it 'should provide a description based on the mime given in describe' do
|
197
|
-
self.class.description.should =~ /with xml$/
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'should run action based on inherited declarations' do
|
201
|
-
@controller.send(:performed?).should_not be_true
|
202
|
-
|
203
|
-
run_action!
|
204
|
-
|
205
|
-
@controller.action_name.should == 'show'
|
206
|
-
@controller.request.method.should == :get
|
207
|
-
@controller.send(:performed?).should be_true
|
208
|
-
@controller.response.body.should == 'XML'
|
209
|
-
@request.parameters[:special_task_id].should == '42'
|
210
|
-
end
|
211
|
-
end
|
212
|
-
|
213
|
-
describe 'and running actions in a before(:all) filter' do
|
214
|
-
get :show, :id => 37
|
215
|
-
|
216
|
-
get! do
|
217
|
-
@request.should_not be_nil
|
218
|
-
end
|
219
|
-
|
220
|
-
get! do
|
221
|
-
@flag = true
|
222
|
-
end
|
223
|
-
|
224
|
-
get! do
|
225
|
-
@controller.should_not be_nil
|
226
|
-
end
|
227
|
-
|
228
|
-
it 'should run the action before each example' do
|
229
|
-
@controller.send(:performed?).should be_true
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'should execute the given block' do
|
233
|
-
@flag.should be_true
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe 'with matcher macros' do
|
239
|
-
|
240
|
-
[:delete, :delete!].each do |method|
|
241
|
-
|
242
|
-
describe method => :destroy, :id => '37' do
|
243
|
-
expects :find, :on => Task, :with => '37', :returns => task_proc
|
204
|
+
get :show, :id => '37' # Execute the action to match expectations
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should run action with stubs' do
|
208
|
+
self.should_receive(:current_id).never
|
209
|
+
run_action!(false)
|
210
|
+
@controller.send(:performed?).should be_true
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should run stubs without performing an action' do
|
214
|
+
self.should_receive(:current_id).never
|
215
|
+
run_stubs!
|
216
|
+
@controller.send(:performed?).should_not be_true
|
217
|
+
end
|
218
|
+
|
219
|
+
describe Mime::XML do
|
220
|
+
expects :to_xml, :on => task_proc, :returns => 'XML'
|
221
|
+
|
222
|
+
it 'should provide a description based on the mime given in describe' do
|
223
|
+
self.class.description.should =~ /with xml$/
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'should run action based on inherited declarations' do
|
227
|
+
@controller.send(:performed?).should_not be_true
|
228
|
+
|
229
|
+
run_action!
|
230
|
+
|
231
|
+
@controller.action_name.should == 'show'
|
232
|
+
@controller.request.method.should == :get
|
233
|
+
@controller.send(:performed?).should be_true
|
234
|
+
@controller.response.body.should == 'XML'
|
235
|
+
@request.parameters[:special_task_id].should == '42'
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'and running actions in a before(:all) filter' do
|
240
|
+
get :show, :id => 37
|
241
|
+
|
242
|
+
get! do
|
243
|
+
@request.should_not be_nil
|
244
|
+
end
|
245
|
+
|
246
|
+
get! do
|
247
|
+
@flag = true
|
248
|
+
end
|
249
|
+
|
250
|
+
get! do
|
251
|
+
@controller.should_not be_nil
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should run the action before each example' do
|
255
|
+
@controller.send(:performed?).should be_true
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'should execute the given block' do
|
259
|
+
@flag.should be_true
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'with matcher macros' do
|
265
|
+
|
266
|
+
[:delete, :delete!].each do |method|
|
267
|
+
|
268
|
+
describe method => :destroy, :id => '37' do
|
269
|
+
expects :find, :on => Task, :with => '37', :returns => task_proc
|
244
270
|
expects :destroy, :on => task_proc
|
245
271
|
expects :title, :on => task_proc, :with => false do |boolean|
|
246
272
|
if boolean
|
@@ -248,47 +274,47 @@ describe 'MacroStubs' do
|
|
248
274
|
else
|
249
275
|
'My favourite task'
|
250
276
|
end
|
251
|
-
end
|
252
|
-
|
253
|
-
xhr!
|
254
|
-
subject { controller }
|
255
|
-
|
256
|
-
should_assign_to :task
|
257
|
-
should_assign_to :task, :with => task_proc
|
258
|
-
should_assign_to :task, :with_kind_of => Task
|
259
|
-
|
260
|
-
should_set_the_flash
|
261
|
-
should_set_the_flash :notice
|
262
|
-
should_set_the_flash :notice, :to => %{"My favourite task" was removed}
|
263
|
-
|
264
|
-
should_set_session
|
265
|
-
should_set_session :last_task_id
|
266
|
-
should_set_session :last_task_id, :to => 37
|
267
|
-
|
268
|
-
should_redirect_to{ project_tasks_url(10) }
|
269
|
-
should_redirect_to proc{ project_tasks_url(10) }, :with => 302
|
270
|
-
|
271
|
-
it 'should run action declared in describe' do
|
272
|
-
@controller.send(:performed?).should_not be_true unless method == :delete!
|
273
|
-
|
274
|
-
run_action!
|
275
|
-
|
276
|
-
@controller.action_name.should == 'destroy'
|
277
|
-
@controller.request.method.should == :delete
|
278
|
-
@controller.send(:performed?).should be_true
|
279
|
-
end
|
280
|
-
|
281
|
-
it 'should provide a description based on parameters given in describe' do
|
282
|
-
self.class.description.should =~ /responding to #DELETE destroy$/
|
277
|
+
end
|
278
|
+
|
279
|
+
xhr!
|
280
|
+
subject { controller }
|
281
|
+
|
282
|
+
should_assign_to :task
|
283
|
+
should_assign_to :task, :with => task_proc
|
284
|
+
should_assign_to :task, :with_kind_of => Task
|
285
|
+
|
286
|
+
should_set_the_flash
|
287
|
+
should_set_the_flash :notice
|
288
|
+
should_set_the_flash :notice, :to => %{"My favourite task" was removed}
|
289
|
+
|
290
|
+
should_set_session
|
291
|
+
should_set_session :last_task_id
|
292
|
+
should_set_session :last_task_id, :to => 37
|
293
|
+
|
294
|
+
should_redirect_to{ project_tasks_url(10) }
|
295
|
+
should_redirect_to proc{ project_tasks_url(10) }, :with => 302
|
296
|
+
|
297
|
+
it 'should run action declared in describe' do
|
298
|
+
@controller.send(:performed?).should_not be_true unless method == :delete!
|
299
|
+
|
300
|
+
run_action!
|
301
|
+
|
302
|
+
@controller.action_name.should == 'destroy'
|
303
|
+
@controller.request.method.should == :delete
|
304
|
+
@controller.send(:performed?).should be_true
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should provide a description based on parameters given in describe' do
|
308
|
+
self.class.description.should =~ /responding to #DELETE destroy$/
|
283
309
|
end
|
284
310
|
|
285
311
|
it 'should perform a XmlHttpRequest' do
|
286
312
|
run_action!
|
287
313
|
request.env['HTTP_X_REQUESTED_WITH'].should == 'XMLHttpRequest'
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
292
|
-
|
293
|
-
end
|
294
|
-
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
end
|
318
|
+
|
319
|
+
end
|
320
|
+
end
|