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.
Files changed (38) hide show
  1. data/CHANGELOG +91 -88
  2. data/LICENSE +20 -20
  3. data/README +80 -80
  4. data/lib/remarkable_rails/action_controller/base.rb +29 -29
  5. data/lib/remarkable_rails/action_controller/macro_stubs.rb +459 -457
  6. data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +92 -92
  7. data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +41 -41
  8. data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +119 -119
  9. data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +146 -146
  10. data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +126 -126
  11. data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +135 -109
  12. data/lib/remarkable_rails/action_controller/matchers/set_cookies_matcher.rb +49 -49
  13. data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +106 -106
  14. data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +54 -54
  15. data/lib/remarkable_rails/action_controller.rb +22 -22
  16. data/lib/remarkable_rails/action_view/base.rb +7 -7
  17. data/lib/remarkable_rails/action_view.rb +18 -18
  18. data/lib/remarkable_rails/active_orm.rb +19 -19
  19. data/lib/remarkable_rails.rb +30 -30
  20. data/locale/en.yml +110 -110
  21. data/spec/action_controller/assign_to_matcher_spec.rb +142 -142
  22. data/spec/action_controller/filter_params_matcher_spec.rb +64 -64
  23. data/spec/action_controller/macro_stubs_spec.rb +234 -208
  24. data/spec/action_controller/redirect_to_matcher_spec.rb +102 -102
  25. data/spec/action_controller/render_template_matcher_spec.rb +251 -251
  26. data/spec/action_controller/respond_with_matcher_spec.rb +223 -223
  27. data/spec/action_controller/route_matcher_spec.rb +96 -79
  28. data/spec/action_controller/set_cookies_matcher_spec.rb +149 -149
  29. data/spec/action_controller/set_session_matcher_spec.rb +141 -141
  30. data/spec/action_controller/set_the_flash_matcher_spec.rb +93 -93
  31. data/spec/application/application.rb +15 -15
  32. data/spec/application/tasks_controller.rb +34 -34
  33. data/spec/functional_builder.rb +88 -88
  34. data/spec/rcov.opts +2 -2
  35. data/spec/remarkable_rails_spec.rb +5 -5
  36. data/spec/spec.opts +4 -4
  37. data/spec/spec_helper.rb +42 -42
  38. metadata +7 -7
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ * Allow should route(:get, :action => :show, :id => 1).to("/projects/1") and
2
+ should route(:get, "/projects/1").from(:action => :show, :id => 1) syntax.
3
+
1
4
  * Plugin files are automatically loaded [#86]
2
5
 
3
6
  * Allow should_route to use environment configuration [#88] (thanks to Lawrence Pit)
@@ -12,91 +15,91 @@
12
15
 
13
16
  * assert_valid_keys on expects
14
17
 
15
- * mock_models now creates a second class method to be used on the index action [#71]
16
- In other words, mock_models :project will create:
17
-
18
- def self.mock_project
19
- proc { mock_project }
20
- end
21
-
22
- # This was added to be used on index actions
23
- def self.mock_projects
24
- proc { [ mock_project ] }
25
- end
26
-
27
- def mock_project(stubs={})
28
- @project ||= mock_model(Project, stubs)
29
- end
30
-
31
- * Allow multiple args to be given to :with in expects. If you need to verify that
32
- an array is being sent, you need to send an array inside another array [#70]
33
-
34
- * Allow procs or blocks to be given to respond_with_body and respond_with :body [#67]
35
-
36
- * Allow ordered to be given to macro stubs as option [#66]
37
-
38
- # v3.1
39
-
40
- * Ensure set_cookies and set_session work with arrays [#55]
41
-
42
- * Added set_cookies matcher [#51]
43
-
44
- * Add a helper to declare that a XmlHttpRequest should be performed:
45
-
46
- describe :get => :show do
47
- xhr!
48
-
49
- * Macro stubs now supports blocks too [#50]
50
-
51
- expects :human_attribute_name, :on => Project, :with => :title do |attr|
52
- attr.to_s.humanize
53
- end
54
-
55
- * :to option in set_session and set_the_flash now accepts Regexp [#46]
56
-
57
- * render_template now works with partials [#43]
58
-
59
- * Added to support for routing example group (inside spec/routing) [#26]
60
-
61
- # v3.0
62
-
63
- * redirect_to and render_template were ported from rspec-rails to
64
- remarkable to provide I18n. The second was also extended to deal with :with,
65
- :layout and :content_type as options.
66
-
67
- render_with_layout, render_without_layout delegate their logic to render_template
68
- so they share the same options.
69
-
70
- respond_with_content_type and respond_wity_body delegate their logic to
71
- respond_with matcher, so they also share the same options.
72
-
73
- :set_the_flash was also redesign to inherit from :set_session, providing a
74
- consistent API.
75
-
76
- * remarkable_rails now ships with a new feature, called macro stubs.
77
- This allows you to declare just once your mocks and/or expectations, and each
78
- matcher will know how to deal with properly. A TasksController could have your
79
- specs for a create action rewritten like this:
80
-
81
- describe TasksController do
82
- mock_models :task
83
-
84
- describe :post => :create, :task => { :these => 'params' } do
85
- expects :new, :on => Task, with => {'these' => 'params'}, :returns => task_proc
86
- expects :save, :on => mock_task, :returns => true
87
-
88
- should_assign_to :task, :with => task_proc
89
- should_redirect_to { task_url(mock_task) }
90
- end
91
- end
92
-
93
- It automatically performs the action before running each macro. In assign_to,
94
- it executes the expects as expectations (:should_receive), and in redirect_to
95
- it executes the expects as stubs (:stub!), just as above.
96
-
97
- For more options, information and configuration, check macro stubs documentation.
98
-
99
- # v2.x
100
-
101
- * Added assign_to, filter_params, render_with_layout, respond_with
102
- respond_with_content_type, route, set_session and set_the_flash matchers.
18
+ * mock_models now creates a second class method to be used on the index action [#71]
19
+ In other words, mock_models :project will create:
20
+
21
+ def self.mock_project
22
+ proc { mock_project }
23
+ end
24
+
25
+ # This was added to be used on index actions
26
+ def self.mock_projects
27
+ proc { [ mock_project ] }
28
+ end
29
+
30
+ def mock_project(stubs={})
31
+ @project ||= mock_model(Project, stubs)
32
+ end
33
+
34
+ * Allow multiple args to be given to :with in expects. If you need to verify that
35
+ an array is being sent, you need to send an array inside another array [#70]
36
+
37
+ * Allow procs or blocks to be given to respond_with_body and respond_with :body [#67]
38
+
39
+ * Allow ordered to be given to macro stubs as option [#66]
40
+
41
+ # v3.1
42
+
43
+ * Ensure set_cookies and set_session work with arrays [#55]
44
+
45
+ * Added set_cookies matcher [#51]
46
+
47
+ * Add a helper to declare that a XmlHttpRequest should be performed:
48
+
49
+ describe :get => :show do
50
+ xhr!
51
+
52
+ * Macro stubs now supports blocks too [#50]
53
+
54
+ expects :human_attribute_name, :on => Project, :with => :title do |attr|
55
+ attr.to_s.humanize
56
+ end
57
+
58
+ * :to option in set_session and set_the_flash now accepts Regexp [#46]
59
+
60
+ * render_template now works with partials [#43]
61
+
62
+ * Added to support for routing example group (inside spec/routing) [#26]
63
+
64
+ # v3.0
65
+
66
+ * redirect_to and render_template were ported from rspec-rails to
67
+ remarkable to provide I18n. The second was also extended to deal with :with,
68
+ :layout and :content_type as options.
69
+
70
+ render_with_layout, render_without_layout delegate their logic to render_template
71
+ so they share the same options.
72
+
73
+ respond_with_content_type and respond_wity_body delegate their logic to
74
+ respond_with matcher, so they also share the same options.
75
+
76
+ :set_the_flash was also redesign to inherit from :set_session, providing a
77
+ consistent API.
78
+
79
+ * remarkable_rails now ships with a new feature, called macro stubs.
80
+ This allows you to declare just once your mocks and/or expectations, and each
81
+ matcher will know how to deal with properly. A TasksController could have your
82
+ specs for a create action rewritten like this:
83
+
84
+ describe TasksController do
85
+ mock_models :task
86
+
87
+ describe :post => :create, :task => { :these => 'params' } do
88
+ expects :new, :on => Task, with => {'these' => 'params'}, :returns => task_proc
89
+ expects :save, :on => mock_task, :returns => true
90
+
91
+ should_assign_to :task, :with => task_proc
92
+ should_redirect_to { task_url(mock_task) }
93
+ end
94
+ end
95
+
96
+ It automatically performs the action before running each macro. In assign_to,
97
+ it executes the expects as expectations (:should_receive), and in redirect_to
98
+ it executes the expects as stubs (:stub!), just as above.
99
+
100
+ For more options, information and configuration, check macro stubs documentation.
101
+
102
+ # v2.x
103
+
104
+ * Added assign_to, filter_params, render_with_layout, respond_with
105
+ respond_with_content_type, route, set_session and set_the_flash matchers.
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 Carlos Brando
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009 Carlos Brando
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README CHANGED
@@ -1,11 +1,11 @@
1
- = Remarkable Rails
2
-
3
- Remarkable Rails is a collection of matchers to Rails. This package has some
4
- ActionController matchers and soon some ActionView matchers.
5
-
1
+ = Remarkable Rails
2
+
3
+ Remarkable Rails is a collection of matchers to Rails. This package has some
4
+ ActionController matchers and soon some ActionView matchers.
5
+
6
6
  Whenever using the Remarkable Rails gem, it will automatically add your ActiveRecord
7
- matchers. So just one line is needed to install both:
8
-
7
+ matchers. So just one line is needed to install both:
8
+
9
9
  sudo gem install remarkable_rails
10
10
 
11
11
  If you are using Rails 2.3, you need to have this configuration on your
@@ -18,82 +18,82 @@ config/environments/test.rb:
18
18
  And then require remarkable inside your spec_helper.rb, after "spec/rails":
19
19
 
20
20
  require 'spec/rails'
21
- require 'remarkable_rails'
22
-
23
- == Matchers & Macros
24
-
25
- The supported matchers and macros are:
26
-
27
- assign_to, filter_params, render_with_layout, respond_with,
28
- respond_with_content_type, route, set_session and set_the_flash matchers.
29
-
30
- In Remarkable 3.0, we also ported and extended redirect to and render template
31
- from rspec rails matchers to provide I18n. You can also do:
32
-
33
- render_template 'edit', :layout => 'default'
34
- respond_with 404, :content_type => Mime::XML, :body => /Not found/
35
-
36
- == Macro stubs
37
-
38
- Another cool feature in Remarkable 3.0 is macro stubs, which makes your mocks
39
- and stubs DRY and easier to maintain. An rspec default scaffold would be:
40
-
41
- describe TasksController do
42
- def mock_task(stubs={})
43
- @task ||= mock_model(Task, stubs)
44
- end
45
-
46
- describe “responding to #POST create” do
47
- it "exposes a newly created task as @task" do
48
- Task.should_receive(:new).with({'these' => 'params'}).
49
- and_return(mock_task(:save => true))
50
- post :create, :task => {:these => 'params'}
51
- assigns[:task].should equal(mock_task)
52
- end
53
-
54
- it "redirects to the created task" do
55
- Task.stub!(:new).and_return(mock_task(:save => true))
56
- post :create, :task => {}
57
- response.should redirect_to(task_url(mock_task))
58
- end
59
- end
60
- end
61
-
62
- An equivalent in remarkable would be:
63
-
64
- describe TasksController do
65
- mock_models :task
66
-
67
- describe :post => :create, :task => { :these => 'params' } do
68
- expects :new, :on => Task, :with => {'these' => 'params'}, :returns => task_proc
69
- expects :save, :on => task_proc, :returns => true
70
-
71
- should_assign_to :task, :with => task_proc
72
- should_redirect_to { task_url(task_proc) }
73
- end
74
- end
75
-
21
+ require 'remarkable_rails'
22
+
23
+ == Matchers & Macros
24
+
25
+ The supported matchers and macros are:
26
+
27
+ assign_to, filter_params, render_with_layout, respond_with,
28
+ respond_with_content_type, route, set_session and set_the_flash matchers.
29
+
30
+ In Remarkable 3.0, we also ported and extended redirect to and render template
31
+ from rspec rails matchers to provide I18n. You can also do:
32
+
33
+ render_template 'edit', :layout => 'default'
34
+ respond_with 404, :content_type => Mime::XML, :body => /Not found/
35
+
36
+ == Macro stubs
37
+
38
+ Another cool feature in Remarkable 3.0 is macro stubs, which makes your mocks
39
+ and stubs DRY and easier to maintain. An rspec default scaffold would be:
40
+
41
+ describe TasksController do
42
+ def mock_task(stubs={})
43
+ @task ||= mock_model(Task, stubs)
44
+ end
45
+
46
+ describe “responding to #POST create” do
47
+ it "exposes a newly created task as @task" do
48
+ Task.should_receive(:new).with({'these' => 'params'}).
49
+ and_return(mock_task(:save => true))
50
+ post :create, :task => {:these => 'params'}
51
+ assigns[:task].should equal(mock_task)
52
+ end
53
+
54
+ it "redirects to the created task" do
55
+ Task.stub!(:new).and_return(mock_task(:save => true))
56
+ post :create, :task => {}
57
+ response.should redirect_to(task_url(mock_task))
58
+ end
59
+ end
60
+ end
61
+
62
+ An equivalent in remarkable would be:
63
+
64
+ describe TasksController do
65
+ mock_models :task
66
+
67
+ describe :post => :create, :task => { :these => 'params' } do
68
+ expects :new, :on => Task, :with => {'these' => 'params'}, :returns => task_proc
69
+ expects :save, :on => task_proc, :returns => true
70
+
71
+ should_assign_to :task, :with => task_proc
72
+ should_redirect_to { task_url(task_proc) }
73
+ end
74
+ end
75
+
76
76
  It automatically performs the action before running each macro. It executes the
77
77
  expects as expectations (:should_receive), but you can supply :with_stubs => true
78
- if you want it to be executed with stubs.
79
-
80
- There are also params and mime methods:
81
-
82
- describe TasksController
83
- params :project_id => 42
84
- mime Mime::HTML
85
-
86
- describe :get => :show, :id => 37 do
87
- should_assign_to :project, :task
88
-
89
- describe Mime::XML do
90
- should_assign_to :project, :task
91
- end
92
- end
93
- end
94
-
78
+ if you want it to be executed with stubs.
79
+
80
+ There are also params and mime methods:
81
+
82
+ describe TasksController
83
+ params :project_id => 42
84
+ mime Mime::HTML
85
+
86
+ describe :get => :show, :id => 37 do
87
+ should_assign_to :project, :task
88
+
89
+ describe Mime::XML do
90
+ should_assign_to :project, :task
91
+ end
92
+ end
93
+ end
94
+
95
95
  And much more. Be sure to check macro stubs documentation.
96
-
96
+
97
97
  == Rails plugin developers
98
98
 
99
99
  Remarkable automatically loads files at the remarkable directory on your plugins
@@ -1,31 +1,31 @@
1
- module Remarkable
2
- module ActionController
3
- class Base < Remarkable::Base
4
-
5
- before_assert :perform_action_with_macro_stubs
1
+ module Remarkable
2
+ module ActionController
3
+ class Base < Remarkable::Base
6
4
 
7
- optional :with_expectations, :default => true
8
- optional :with_stubs, :default => true
5
+ before_assert :perform_action_with_macro_stubs
9
6
 
10
- protected
11
-
12
- # Before assertions, call run_action! to perform the action if it was
13
- # not performed yet.
14
- #
15
- def perform_action_with_macro_stubs #:nodoc:
16
- @spec.send(:run_action!, run_with_expectations?) if @spec.send(:controller)
17
- end
18
-
19
- def run_with_expectations? #:nodoc:
20
- if @options.key?(:with_stubs)
21
- !@options[:with_stubs]
22
- elsif @options.key?(:with_expectations)
23
- @options[:with_expectations]
24
- else
25
- true
26
- end
27
- end
28
-
29
- end
30
- end
31
- end
7
+ optional :with_expectations, :default => true
8
+ optional :with_stubs, :default => true
9
+
10
+ protected
11
+
12
+ # Before assertions, call run_action! to perform the action if it was
13
+ # not performed yet.
14
+ #
15
+ def perform_action_with_macro_stubs #:nodoc:
16
+ @spec.send(:run_action!, run_with_expectations?) if @spec.send(:controller)
17
+ end
18
+
19
+ def run_with_expectations? #:nodoc:
20
+ if @options.key?(:with_stubs)
21
+ !@options[:with_stubs]
22
+ elsif @options.key?(:with_expectations)
23
+ @options[:with_expectations]
24
+ else
25
+ true
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end