remarkable_rails 3.1.4 → 3.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ * [DEPRECATION] By default all matchers perform expectations, use with_stubs => true
2
+ if you want otherwise.
3
+
4
+ * [DEPRECATION] mock_models now creates model_proc instead of mock_model.
5
+ Altough this won't fire any deprecation warning, all the documentation was changed.
6
+
1
7
  * assert_valid_keys on expects
2
8
 
3
9
  * mock_models now creates a second class method to be used on the index action [#71]
@@ -70,10 +76,10 @@ specs for a create action rewritten like this:
70
76
  mock_models :task
71
77
 
72
78
  describe :post => :create, :task => { :these => 'params' } do
73
- expects :new, :on => Task, with => {'these' => 'params'}, :returns => mock_task
79
+ expects :new, :on => Task, with => {'these' => 'params'}, :returns => task_proc
74
80
  expects :save, :on => mock_task, :returns => true
75
81
 
76
- should_assign_to :task, :with => mock_task
82
+ should_assign_to :task, :with => task_proc
77
83
  should_redirect_to { task_url(mock_task) }
78
84
  end
79
85
  end
data/README CHANGED
@@ -65,17 +65,17 @@ An equivalent in remarkable would be:
65
65
  mock_models :task
66
66
 
67
67
  describe :post => :create, :task => { :these => 'params' } do
68
- expects :new, :on => Task, :with => {'these' => 'params'}, :returns => mock_task
69
- expects :save, :on => mock_task, :returns => true
68
+ expects :new, :on => Task, :with => {'these' => 'params'}, :returns => task_proc
69
+ expects :save, :on => task_proc, :returns => true
70
70
 
71
- should_assign_to :task, :with => mock_task
72
- should_redirect_to { task_url(mock_task) }
71
+ should_assign_to :task, :with => task_proc
72
+ should_redirect_to { task_url(task_proc) }
73
73
  end
74
74
  end
75
75
 
76
- It automatically performs the action before running each macro. In assign_to,
77
- it executes the expects as expectations (:should_receive), and in redirect_to
78
- it executes the expects as stubs (:stub!), just as above.
76
+ It automatically performs the action before running each macro. It executes the
77
+ expects as expectations (:should_receive), but you can supply :with_stubs => true
78
+ if you want it to be executed with stubs.
79
79
 
80
80
  There are also params and mime methods:
81
81
 
@@ -3,10 +3,10 @@ module Remarkable
3
3
  class Base < Remarkable::Base
4
4
 
5
5
  before_assert :perform_action_with_macro_stubs
6
-
6
+
7
7
  optional :with_expectations, :default => true
8
8
  optional :with_stubs, :default => true
9
-
9
+
10
10
  protected
11
11
 
12
12
  # Before assertions, call run_action! to perform the action if it was
@@ -22,7 +22,7 @@ module Remarkable
22
22
  elsif @options.key?(:with_expectations)
23
23
  @options[:with_expectations]
24
24
  else
25
- false
25
+ true
26
26
  end
27
27
  end
28
28
 
@@ -36,27 +36,16 @@ module Remarkable
36
36
  # assigns(:project).should == mock_project
37
37
  # end
38
38
  #
39
- # On the other hand, should render template is doing something like this:
40
- #
41
- # it 'should render template show' do
42
- # Project.stub!(:find).and_return(mock_project)
43
- # get :show, :id => '37'
44
- # response.should render_template('show')
45
- # end
46
- #
47
- # Now comes the first question: how each macro knows if they should perform
48
- # expectations or stubs?
49
- #
50
- # By default, only should_assign_to macro performs expectations. You can change
39
+ # By default, all macros perform expectations. You can change
51
40
  # this behavior sending :with_stubs or :with_expectations as options:
52
41
  #
53
42
  # should_assign_to :project, :with_stubs => true
54
- # should_render_template 'show', :with_expectations => true
43
+ # should_render_template 'show', :with_expectations => false
55
44
  #
56
45
  # This also works in the rspec way:
57
46
  #
58
- # it { should assign_to(:project).with_stubs }
59
- # it { should render_template('show').with_expectations }
47
+ # it { should assign_to(:project).with_stubs }
48
+ # it { should render_template('show').with_expectations(false) }
60
49
  #
61
50
  # == Attention!
62
51
  #
@@ -84,12 +73,12 @@ module Remarkable
84
73
  #
85
74
  # And it creates:
86
75
  #
87
- # def self.mock_project
76
+ # def self.project_proc
88
77
  # proc { mock_project }
89
78
  # end
90
79
  #
91
80
  # # To be used on index actions
92
- # def self.mock_projects
81
+ # def self.projects_proc
93
82
  # proc { [mock_project] }
94
83
  # end
95
84
  #
@@ -104,8 +93,8 @@ module Remarkable
104
93
  #
105
94
  # For:
106
95
  #
107
- # expects :find, :on => Project, :with => '37', :returns => mock_project
108
- # should_assign_to :project, :with => mock_project
96
+ # expects :find, :on => Project, :with => '37', :returns => project_proc
97
+ # should_assign_to :project, :with => project_proc
109
98
  #
110
99
  # = Give me more!
111
100
  #
@@ -122,11 +111,11 @@ module Remarkable
122
111
  # params :project_id => '42' #=> define params for all requests
123
112
  #
124
113
  # # Those two expectations get inherited in all describe groups below
125
- # expects :find_by_title, :on => Project, :with => '42', :returns => mock_project
114
+ # expects :find_by_title, :on => Project, :with => '42', :returns => project_proc
126
115
  # expects :tasks, :and_return => Task
127
116
  #
128
117
  # describe :get => :show, :id => '37' do
129
- # expects :find, :with => '37', :and_return => mock_task
118
+ # expects :find, :with => '37', :and_return => task_proc
130
119
  #
131
120
  # should_assign_to :project, :task
132
121
  # should_render_template 'show'
@@ -140,7 +129,7 @@ module Remarkable
140
129
  # expectations with run_action!, run_expectations! and run_stubs!. Examples:
141
130
  #
142
131
  # describe :get => :new do
143
- # expects :new, :on => Project, :returns => mock_project
132
+ # expects :new, :on => Project, :returns => project_proc
144
133
  #
145
134
  # it "should do something different" do
146
135
  # run_action!
@@ -223,9 +212,9 @@ module Remarkable
223
212
  #
224
213
  # == Example
225
214
  #
226
- # expects :new, :on => Project, :returns => :mock_project, :times => 2
215
+ # expects :new, :on => Project, :returns => :project_proc, :times => 2
227
216
  #
228
- # expects :new, :find, :on => Project, :returns => :mock_project
217
+ # expects :new, :find, :on => Project, :returns => :project_proc
229
218
  #
230
219
  # expects :human_attribute_name, :on => Project, :with => :title do |attr|
231
220
  # attr.to_s.humanize
@@ -429,12 +418,12 @@ module Remarkable
429
418
  #
430
419
  # Will create one instance and two class mock methods for you:
431
420
  #
432
- # def self.mock_project
421
+ # def self.project_proc
433
422
  # proc { mock_project }
434
423
  # end
435
424
  #
436
425
  # # To be used on index actions
437
- # def self.mock_projects
426
+ # def self.projects_procs
438
427
  # proc { [ mock_project ] }
439
428
  # end
440
429
  #
@@ -450,11 +439,18 @@ module Remarkable
450
439
  options = { :class_method => true }.merge(options)
451
440
 
452
441
  models.each do |model|
453
- model = model.to_s
454
- self.class_eval <<-METHOD
455
- #{"def self.mock_#{model}; proc { mock_#{model} }; end" if options[:class_method]}
456
- #{"def self.mock_#{model.pluralize}; proc { [ mock_#{model} ] }; end" if options[:class_method]}
442
+ model = model.to_s
443
+ if options[:class_method]
444
+ (class << self; self; end).class_eval <<-METHOD
445
+ def #{model}_proc; proc { mock_#{model} }; end
446
+ def #{model.pluralize}_proc; proc { [ mock_#{model} ] }; end
447
+
448
+ alias :mock_#{model} :#{model}_proc
449
+ alias :mock_#{model.pluralize} :#{model.pluralize}_proc
450
+ METHOD
451
+ end
457
452
 
453
+ self.class_eval <<-METHOD
458
454
  def mock_#{model}(stubs={})
459
455
  @#{model} ||= mock_model(#{model.classify}, stubs)
460
456
  end
@@ -11,8 +11,6 @@ module Remarkable
11
11
 
12
12
  before_assert :evaluate_expected_value
13
13
 
14
- default_options :with_expectations => true
15
-
16
14
  protected
17
15
 
18
16
  def assigned_value?
@@ -11,21 +11,29 @@ describe 'MacroStubs' do
11
11
 
12
12
  describe 'mock_models' do
13
13
  before(:each) do
14
- self.class.metaclass.send(:undef_method, :mock_projects) if self.class.respond_to?(:mock_projects)
15
- self.class.metaclass.send(:undef_method, :mock_project) if self.class.respond_to?(:mock_project)
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
16
  self.class.send(:undef_method, :mock_project) if self.respond_to?(:mock_project)
17
17
  end
18
+
19
+ it 'should alias model_proc to mock_model' do
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
23
+ self.class.respond_to?(:mock_project).should be_true
24
+ self.class.respond_to?(:mock_projects).should be_true
25
+ end
18
26
 
19
27
  it 'should create a class singular mock method' do
20
- self.class.respond_to?(:mock_project).should be_false
28
+ self.class.respond_to?(:project_proc).should be_false
21
29
  self.class.mock_models :project
22
- self.class.respond_to?(:mock_project).should be_true
30
+ self.class.respond_to?(:project_proc).should be_true
23
31
  end
24
32
 
25
33
  it 'should create a class plural mock method' do
26
- self.class.respond_to?(:mock_projects).should be_false
34
+ self.class.respond_to?(:projects_proc).should be_false
27
35
  self.class.mock_models :project
28
- self.class.respond_to?(:mock_projects).should be_true
36
+ self.class.respond_to?(:projects_proc).should be_true
29
37
  end
30
38
 
31
39
  it 'should create an instance mock method' do
@@ -35,15 +43,15 @@ describe 'MacroStubs' do
35
43
  end
36
44
 
37
45
  it 'should create just an instance method when :class_method is false' do
38
- self.class.respond_to?(:mock_project).should be_false
46
+ self.class.respond_to?(:project_proc).should be_false
39
47
  self.respond_to?(:mock_project).should be_false
40
48
  self.class.mock_models :project, :class_method => false
41
- self.class.respond_to?(:mock_project).should be_false
49
+ self.class.respond_to?(:project_proc).should be_false
42
50
  self.respond_to?(:mock_project).should be_true
43
51
  end
44
52
 
45
53
  it 'should create procs which evals to a mock dynamically' do
46
- proc = self.class.mock_task
54
+ proc = self.class.task_proc
47
55
  proc.should be_kind_of(Proc)
48
56
 
49
57
  @task.should be_nil
@@ -52,7 +60,7 @@ describe 'MacroStubs' do
52
60
  end
53
61
 
54
62
  it 'should create procs which evals to an array of mocks dynamically' do
55
- proc = self.class.mock_tasks
63
+ proc = self.class.tasks_proc
56
64
  proc.should be_kind_of(Proc)
57
65
 
58
66
  @task.should be_nil
@@ -62,7 +70,7 @@ describe 'MacroStubs' do
62
70
  end
63
71
 
64
72
  describe 'failures' do
65
- expects :find, :on => Task, :with => proc{ current_id }, :returns => mock_task
73
+ expects :find, :on => Task, :with => proc{ current_id }, :returns => task_proc
66
74
  expects :max, :min, :count, :on => Task, :ordered => true
67
75
 
68
76
  get :show, :id => 37
@@ -109,7 +117,7 @@ describe 'MacroStubs' do
109
117
  end
110
118
 
111
119
  describe 'when extending describe group behavior' do
112
- expects :find, :on => Task, :with => proc{ current_id }, :returns => mock_task
120
+ expects :find, :on => Task, :with => proc{ current_id }, :returns => task_proc
113
121
  expects :count, :max, :min, :on => Task
114
122
 
115
123
  get :show, :id => 37
@@ -176,7 +184,7 @@ describe 'MacroStubs' do
176
184
  end
177
185
 
178
186
  describe Mime::XML do
179
- expects :to_xml, :on => mock_task, :returns => 'XML'
187
+ expects :to_xml, :on => task_proc, :returns => 'XML'
180
188
 
181
189
  it 'should provide a description based on the mime given in describe' do
182
190
  self.class.description.should =~ /with xml$/
@@ -225,9 +233,9 @@ describe 'MacroStubs' do
225
233
  [:delete, :delete!].each do |method|
226
234
 
227
235
  describe method => :destroy, :id => '37' do
228
- expects :find, :on => Task, :with => '37', :returns => mock_task
229
- expects :destroy, :on => mock_task
230
- expects :title, :on => mock_task, :with => false do |boolean|
236
+ expects :find, :on => Task, :with => '37', :returns => task_proc
237
+ expects :destroy, :on => task_proc
238
+ expects :title, :on => task_proc, :with => false do |boolean|
231
239
  if boolean
232
240
  'This should not appear'
233
241
  else
@@ -239,7 +247,7 @@ describe 'MacroStubs' do
239
247
  subject { controller }
240
248
 
241
249
  should_assign_to :task
242
- should_assign_to :task, :with => mock_task
250
+ should_assign_to :task, :with => task_proc
243
251
  should_assign_to :task, :with_kind_of => Task
244
252
 
245
253
  should_set_the_flash
@@ -55,10 +55,9 @@ module FunctionalBuilder
55
55
 
56
56
  module ClassMethods
57
57
  def generate_macro_stubs_specs_for(matcher, *args)
58
- stubs_args = args.dup
59
-
60
- options = args.extract_options!
61
- expectations_args = (args << options.merge(:with_expectations => true))
58
+ expectation_args = args.dup
59
+ options = args.extract_options!
60
+ stub_args = (args << options.merge(:with_stubs => true))
62
61
 
63
62
  describe 'macro stubs' do
64
63
  before(:each) do
@@ -70,21 +69,21 @@ module FunctionalBuilder
70
69
  expects :new, :on => String, :with => 'ola', :returns => 'ola'
71
70
  get :new
72
71
 
73
- it 'should run stubs by default' do
74
- String.should_receive(:stub!).with(:new).and_return(@mock=mock('chain'))
75
- @mock.should_receive(:and_return).with('ola').and_return('ola')
76
-
77
- send(matcher, *stubs_args).matches?(@controller)
78
- end
79
-
80
- it 'should run expectations' do
72
+ it 'should run expectations by default' do
81
73
  String.should_receive(:should_receive).with(:new).and_return(@mock=mock('chain'))
82
74
  @mock.should_receive(:with).with('ola').and_return(@mock)
83
75
  @mock.should_receive(:exactly).with(1).and_return(@mock)
84
76
  @mock.should_receive(:times).and_return(@mock)
85
77
  @mock.should_receive(:and_return).with('ola').and_return('ola')
86
78
 
87
- send(matcher, *expectations_args).matches?(@controller)
79
+ send(matcher, *expectation_args).matches?(@controller)
80
+ end
81
+
82
+ it 'should run stubs' do
83
+ String.should_receive(:stub!).with(:new).and_return(@mock=mock('chain'))
84
+ @mock.should_receive(:and_return).with('ola').and_return('ola')
85
+
86
+ send(matcher, *stub_args).matches?(@controller)
88
87
  end
89
88
  end
90
89
 
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.1.4
4
+ version: 3.1.5
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-05-29 00:00:00 +02:00
13
+ date: 2009-06-04 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -41,7 +41,7 @@ dependencies:
41
41
  requirements:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
- version: 3.1.4
44
+ version: 3.1.5
45
45
  version:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: remarkable_activerecord
@@ -51,7 +51,7 @@ dependencies:
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 3.1.4
54
+ version: 3.1.5
55
55
  version:
56
56
  description: "Remarkable Rails: collection of matchers and macros with I18n for Rails"
57
57
  email: