remarkable_rails 3.0.1 → 3.0.2
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 +44 -44
- data/LICENSE +1 -1
- data/README +83 -83
- data/lib/remarkable_rails/action_controller/base.rb +24 -24
- data/lib/remarkable_rails/action_controller/macro_stubs.rb +493 -493
- data/lib/remarkable_rails/action_controller/matchers/assign_to_matcher.rb +72 -72
- data/lib/remarkable_rails/action_controller/matchers/filter_params_matcher.rb +21 -21
- data/lib/remarkable_rails/action_controller/matchers/redirect_to_matcher.rb +112 -112
- data/lib/remarkable_rails/action_controller/matchers/render_template_matcher.rb +140 -140
- data/lib/remarkable_rails/action_controller/matchers/respond_with_matcher.rb +118 -118
- data/lib/remarkable_rails/action_controller/matchers/route_matcher.rb +51 -51
- data/lib/remarkable_rails/action_controller/matchers/set_session_matcher.rb +103 -103
- data/lib/remarkable_rails/action_controller/matchers/set_the_flash_matcher.rb +50 -50
- data/lib/remarkable_rails/action_view/base.rb +1 -1
- data/lib/remarkable_rails/action_view.rb +16 -16
- data/lib/remarkable_rails/active_orm.rb +2 -2
- data/locale/en.yml +74 -74
- data/spec/action_controller/assign_to_matcher_spec.rb +68 -68
- data/spec/action_controller/filter_params_matcher_spec.rb +42 -42
- data/spec/action_controller/macro_stubs_spec.rb +17 -17
- data/spec/action_controller/redirect_to_matcher_spec.rb +60 -60
- data/spec/action_controller/render_template_matcher_spec.rb +227 -227
- data/spec/action_controller/respond_with_matcher_spec.rb +189 -189
- data/spec/action_controller/route_matcher_spec.rb +75 -75
- data/spec/action_controller/set_session_matcher_spec.rb +43 -43
- data/spec/action_controller/set_the_flash_matcher_spec.rb +1 -1
- data/spec/application/application.rb +14 -14
- data/spec/application/tasks_controller.rb +34 -34
- data/spec/functional_builder.rb +93 -93
- data/spec/spec_helper.rb +44 -44
- metadata +4 -4
data/CHANGELOG
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
[TODO] Port views matchers from rspec to Remarkable to provide I18n.
|
2
|
-
|
3
|
-
# v3.0.0
|
4
|
-
|
5
|
-
[ENHANCEMENT] redirect_to and render_template were ported from rspec-rails to
|
6
|
-
remarkable to provide I18n. The second was also extended to deal with :with,
|
7
|
-
:layout and :content_type as options.
|
8
|
-
|
9
|
-
render_with_layout, render_without_layout delegate their logic to render_template
|
10
|
-
so they share the same options.
|
11
|
-
|
12
|
-
respond_with_content_type and respond_wity_body delegate their logic to
|
13
|
-
respond_with matcher, so they also share the same options.
|
14
|
-
|
15
|
-
:set_the_flash was also redesign to inherit from :set_session, providing a
|
16
|
-
consistent API.
|
17
|
-
|
18
|
-
[ENHANCEMENT] remarkable_rails now ships with a new feature, called macro stubs.
|
19
|
-
This allows you to declare just once your mocks and/or expectations, and each
|
20
|
-
matcher will know how to deal with properly. A TasksController could have your
|
21
|
-
specs for a create action rewritten like this:
|
22
|
-
|
23
|
-
describe TasksController do
|
24
|
-
mock_models :task
|
25
|
-
|
26
|
-
describe :post => :create, :task => { :these => 'params' } do
|
27
|
-
expects :new, :on => Task, with => {'these' => 'params'}, :returns => mock_task
|
28
|
-
expects :save, :on => mock_task, :returns => true
|
29
|
-
|
30
|
-
should_assign_to :task, :with => mock_task
|
31
|
-
should_redirect_to { task_url(mock_task) }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
It automatically performs the action before running each macro. In assign_to,
|
36
|
-
it executes the expects as expectations (:should_receive), and in redirect_to
|
37
|
-
it executes the expects as stubs (:stub!), just as above.
|
38
|
-
|
39
|
-
For more options, information and configuration, check macro stubs documentation.
|
40
|
-
|
41
|
-
# v2.x
|
42
|
-
|
43
|
-
[ENHANCMENT] Added assign_to, filter_params, render_with_layout, respond_with
|
44
|
-
respond_with_content_type, route, set_session and set_the_flash matchers.
|
1
|
+
[TODO] Port views matchers from rspec to Remarkable to provide I18n.
|
2
|
+
|
3
|
+
# v3.0.0
|
4
|
+
|
5
|
+
[ENHANCEMENT] redirect_to and render_template were ported from rspec-rails to
|
6
|
+
remarkable to provide I18n. The second was also extended to deal with :with,
|
7
|
+
:layout and :content_type as options.
|
8
|
+
|
9
|
+
render_with_layout, render_without_layout delegate their logic to render_template
|
10
|
+
so they share the same options.
|
11
|
+
|
12
|
+
respond_with_content_type and respond_wity_body delegate their logic to
|
13
|
+
respond_with matcher, so they also share the same options.
|
14
|
+
|
15
|
+
:set_the_flash was also redesign to inherit from :set_session, providing a
|
16
|
+
consistent API.
|
17
|
+
|
18
|
+
[ENHANCEMENT] remarkable_rails now ships with a new feature, called macro stubs.
|
19
|
+
This allows you to declare just once your mocks and/or expectations, and each
|
20
|
+
matcher will know how to deal with properly. A TasksController could have your
|
21
|
+
specs for a create action rewritten like this:
|
22
|
+
|
23
|
+
describe TasksController do
|
24
|
+
mock_models :task
|
25
|
+
|
26
|
+
describe :post => :create, :task => { :these => 'params' } do
|
27
|
+
expects :new, :on => Task, with => {'these' => 'params'}, :returns => mock_task
|
28
|
+
expects :save, :on => mock_task, :returns => true
|
29
|
+
|
30
|
+
should_assign_to :task, :with => mock_task
|
31
|
+
should_redirect_to { task_url(mock_task) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
It automatically performs the action before running each macro. In assign_to,
|
36
|
+
it executes the expects as expectations (:should_receive), and in redirect_to
|
37
|
+
it executes the expects as stubs (:stub!), just as above.
|
38
|
+
|
39
|
+
For more options, information and configuration, check macro stubs documentation.
|
40
|
+
|
41
|
+
# v2.x
|
42
|
+
|
43
|
+
[ENHANCMENT] Added assign_to, filter_params, render_with_layout, respond_with
|
44
|
+
respond_with_content_type, route, set_session and set_the_flash matchers.
|
data/LICENSE
CHANGED
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
17
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
18
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
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.
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
CHANGED
@@ -1,83 +1,83 @@
|
|
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
|
-
Whenever using the Remarkable Rails gem and ActiveRecord, it will automatically
|
7
|
-
add your ActiveRecord matchers. So just one line is needed to install both:
|
8
|
-
|
9
|
-
sudo gem install remarkable_rails
|
10
|
-
|
11
|
-
== Matchers & Macros
|
12
|
-
|
13
|
-
The supported matchers and macros are:
|
14
|
-
|
15
|
-
assign_to, filter_params, render_with_layout, respond_with,
|
16
|
-
respond_with_content_type, route, set_session and set_the_flash matchers.
|
17
|
-
|
18
|
-
In Remarkable 3.0, we also ported and extended redirect to and render template
|
19
|
-
from rspec rails matchers to provide I18n. You can also do:
|
20
|
-
|
21
|
-
render_template 'edit', :layout => 'default'
|
22
|
-
respond_with 404, :content_type => Mime::XML, :body => /Not found/
|
23
|
-
|
24
|
-
== Macro stubs
|
25
|
-
|
26
|
-
Another cool feature in Remarkable 3.0 is macro stubs, which makes your mocks
|
27
|
-
and stubs DRY and easier to maintain. An rspec default scaffold would be:
|
28
|
-
|
29
|
-
describe TasksController do
|
30
|
-
def mock_task(stubs={})
|
31
|
-
@task ||= mock_model(Task, stubs)
|
32
|
-
end
|
33
|
-
|
34
|
-
describe “responding to #POST create” do
|
35
|
-
it "exposes a newly created task as @task" do
|
36
|
-
Task.should_receive(:new).with({'these' => 'params'}).
|
37
|
-
and_return(mock_task(:save => true))
|
38
|
-
post :create, :task => {:these => 'params'}
|
39
|
-
assigns[:task].should equal(mock_task)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "redirects to the created task" do
|
43
|
-
Task.stub!(:new).and_return(mock_task(:save => true))
|
44
|
-
post :create, :task => {}
|
45
|
-
response.should redirect_to(task_url(mock_task))
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
An equivalent in remarkable would be:
|
51
|
-
|
52
|
-
describe TasksController do
|
53
|
-
mock_models :task
|
54
|
-
|
55
|
-
describe :post => :create, :task => { :these => 'params' } do
|
56
|
-
expects :new, :on => Task, with => {'these' => 'params'}, :returns => mock_task
|
57
|
-
expects :save, :on => mock_task, :returns => true
|
58
|
-
|
59
|
-
should_assign_to :task, :with => mock_task
|
60
|
-
should_redirect_to { task_url(mock_task) }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
It automatically performs the action before running each macro. In assign_to,
|
65
|
-
it executes the expects as expectations (:should_receive), and in redirect_to
|
66
|
-
it executes the expects as stubs (:stub!), just as above.
|
67
|
-
|
68
|
-
There are also params and mime methods:
|
69
|
-
|
70
|
-
describe TasksController
|
71
|
-
params :project_id => 42
|
72
|
-
mime Mime::HTML
|
73
|
-
|
74
|
-
describe :get => :show, :id => 37 do
|
75
|
-
should_assign_to :project, :task
|
76
|
-
|
77
|
-
describe Mime::XML do
|
78
|
-
should_assign_to :project, :task
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
And much more. Be sure to check macro stubs documentation.
|
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
|
+
Whenever using the Remarkable Rails gem and ActiveRecord, it will automatically
|
7
|
+
add your ActiveRecord matchers. So just one line is needed to install both:
|
8
|
+
|
9
|
+
sudo gem install remarkable_rails
|
10
|
+
|
11
|
+
== Matchers & Macros
|
12
|
+
|
13
|
+
The supported matchers and macros are:
|
14
|
+
|
15
|
+
assign_to, filter_params, render_with_layout, respond_with,
|
16
|
+
respond_with_content_type, route, set_session and set_the_flash matchers.
|
17
|
+
|
18
|
+
In Remarkable 3.0, we also ported and extended redirect to and render template
|
19
|
+
from rspec rails matchers to provide I18n. You can also do:
|
20
|
+
|
21
|
+
render_template 'edit', :layout => 'default'
|
22
|
+
respond_with 404, :content_type => Mime::XML, :body => /Not found/
|
23
|
+
|
24
|
+
== Macro stubs
|
25
|
+
|
26
|
+
Another cool feature in Remarkable 3.0 is macro stubs, which makes your mocks
|
27
|
+
and stubs DRY and easier to maintain. An rspec default scaffold would be:
|
28
|
+
|
29
|
+
describe TasksController do
|
30
|
+
def mock_task(stubs={})
|
31
|
+
@task ||= mock_model(Task, stubs)
|
32
|
+
end
|
33
|
+
|
34
|
+
describe “responding to #POST create” do
|
35
|
+
it "exposes a newly created task as @task" do
|
36
|
+
Task.should_receive(:new).with({'these' => 'params'}).
|
37
|
+
and_return(mock_task(:save => true))
|
38
|
+
post :create, :task => {:these => 'params'}
|
39
|
+
assigns[:task].should equal(mock_task)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "redirects to the created task" do
|
43
|
+
Task.stub!(:new).and_return(mock_task(:save => true))
|
44
|
+
post :create, :task => {}
|
45
|
+
response.should redirect_to(task_url(mock_task))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
An equivalent in remarkable would be:
|
51
|
+
|
52
|
+
describe TasksController do
|
53
|
+
mock_models :task
|
54
|
+
|
55
|
+
describe :post => :create, :task => { :these => 'params' } do
|
56
|
+
expects :new, :on => Task, with => {'these' => 'params'}, :returns => mock_task
|
57
|
+
expects :save, :on => mock_task, :returns => true
|
58
|
+
|
59
|
+
should_assign_to :task, :with => mock_task
|
60
|
+
should_redirect_to { task_url(mock_task) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
It automatically performs the action before running each macro. In assign_to,
|
65
|
+
it executes the expects as expectations (:should_receive), and in redirect_to
|
66
|
+
it executes the expects as stubs (:stub!), just as above.
|
67
|
+
|
68
|
+
There are also params and mime methods:
|
69
|
+
|
70
|
+
describe TasksController
|
71
|
+
params :project_id => 42
|
72
|
+
mime Mime::HTML
|
73
|
+
|
74
|
+
describe :get => :show, :id => 37 do
|
75
|
+
should_assign_to :project, :task
|
76
|
+
|
77
|
+
describe Mime::XML do
|
78
|
+
should_assign_to :project, :task
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
And much more. Be sure to check macro stubs documentation.
|
@@ -1,30 +1,30 @@
|
|
1
1
|
module Remarkable
|
2
2
|
module ActionController
|
3
3
|
class Base < Remarkable::Base
|
4
|
-
|
5
|
-
before_assert :perform_action_with_macro_stubs
|
6
|
-
|
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
|
-
false
|
26
|
-
end
|
27
|
-
end
|
4
|
+
|
5
|
+
before_assert :perform_action_with_macro_stubs
|
6
|
+
|
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
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
29
|
end
|
30
30
|
end
|