rspec-rails 2.5.0 → 2.6.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -4
- data/.travis.yml +11 -0
- data/README_DEV.md +43 -0
- data/Rakefile +54 -27
- data/Thorfile +6 -21
- data/features/Autotest.md +7 -0
- data/features/Changelog.md +17 -2
- data/features/Upgrade.md +13 -12
- data/features/controller_specs/README.md +18 -10
- data/features/controller_specs/anonymous_controller.feature +5 -5
- data/features/controller_specs/controller_spec.feature +1 -1
- data/features/controller_specs/isolation_from_views.feature +2 -2
- data/features/controller_specs/render_views.feature +3 -3
- data/features/helper_specs/helper_spec.feature +3 -3
- data/features/mailer_specs/url_helpers.feature +2 -2
- data/features/matchers/new_record_matcher.feature +2 -2
- data/features/matchers/redirect_to_matcher.feature +1 -1
- data/features/matchers/render_template_matcher.feature +1 -1
- data/features/mocks/mock_model.feature +21 -5
- data/features/mocks/stub_model.feature +2 -2
- data/features/model_specs/errors_on.feature +1 -1
- data/features/model_specs/transactional_examples.feature +10 -5
- data/features/routing_specs/README.md +2 -1
- data/features/routing_specs/be_routable_matcher.feature +5 -5
- data/features/routing_specs/named_routes.feature +1 -1
- data/features/routing_specs/route_to_matcher.feature +28 -8
- data/features/step_definitions/additional_cli_steps.rb +1 -1
- data/features/support/env.rb +7 -18
- data/features/view_specs/inferred_controller_path.feature +3 -3
- data/features/view_specs/stub_template.feature +2 -2
- data/features/view_specs/view_spec.feature +8 -8
- data/gemfiles/base.rb +45 -0
- data/gemfiles/rails-3-0-stable +7 -0
- data/gemfiles/rails-3.0.0 +5 -0
- data/gemfiles/rails-3.0.1 +5 -0
- data/gemfiles/rails-3.0.2 +5 -0
- data/gemfiles/rails-3.0.3 +5 -0
- data/gemfiles/rails-3.0.4 +5 -0
- data/gemfiles/rails-3.0.5 +5 -0
- data/gemfiles/rails-3.0.6 +5 -0
- data/gemfiles/rails-master +7 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +20 -2
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +23 -23
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +7 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -5
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec/rails/example/controller_example_group.rb +9 -1
- data/lib/rspec/rails/example/routing_example_group.rb +1 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +23 -2
- data/lib/rspec/rails/mocks.rb +3 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/version.rb +1 -1
- data/rspec-rails.gemspec +5 -36
- data/spec/autotest/rails_rspec2_spec.rb +2 -7
- data/spec/rspec/rails/example/controller_example_group_spec.rb +25 -0
- data/spec/rspec/rails/matchers/route_to_spec.rb +15 -0
- data/spec/rspec/rails/mocks/ar_classes.rb +5 -2
- data/spec/rspec/rails/view_rendering_spec.rb +0 -6
- data/templates/generate_stuff.rb +2 -1
- data/templates/run_specs.rb +2 -2
- metadata +54 -77
- data/Gemfile-3-0-stable +0 -6
- data/Gemfile-3.0.0 +0 -3
- data/Gemfile-3.0.3 +0 -3
- data/Gemfile-base +0 -38
- data/Gemfile-master +0 -5
- data/specs.watchr +0 -59
- data/templates/Gemfile-base +0 -17
@@ -25,7 +25,7 @@ Feature: helper spec
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
"""
|
28
|
-
When I run
|
28
|
+
When I run `rspec spec/helpers/application_helper_spec.rb`
|
29
29
|
Then the examples should all pass
|
30
30
|
|
31
31
|
Scenario: helper method that accesses an instance variable
|
@@ -50,7 +50,7 @@ Feature: helper spec
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
"""
|
53
|
-
When I run
|
53
|
+
When I run `rspec spec/helpers/application_helper_spec.rb`
|
54
54
|
Then the examples should all pass
|
55
55
|
|
56
56
|
Scenario: application helper is included in helper object
|
@@ -83,5 +83,5 @@ Feature: helper spec
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
"""
|
86
|
-
When I run
|
86
|
+
When I run `rspec spec/helpers/widgets_helper_spec.rb`
|
87
87
|
Then the examples should all pass
|
@@ -15,7 +15,7 @@ Feature: URL helpers in mailer examples
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
"""
|
18
|
-
When I run
|
18
|
+
When I run `rspec spec`
|
19
19
|
Then the examples should all pass
|
20
20
|
|
21
21
|
Scenario: using URL helpers without default options
|
@@ -34,5 +34,5 @@ Feature: URL helpers in mailer examples
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
"""
|
37
|
-
When I run
|
37
|
+
When I run `rspec spec`
|
38
38
|
Then the examples should all pass
|
@@ -24,7 +24,7 @@ Feature: be_a_new matcher
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
"""
|
27
|
-
When I run
|
27
|
+
When I run `rspec spec/models/widget_spec.rb`
|
28
28
|
Then the examples should all pass
|
29
29
|
|
30
30
|
Scenario: example spec using be_a_new.with
|
@@ -66,5 +66,5 @@ Feature: be_a_new matcher
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
"""
|
69
|
-
When I run
|
69
|
+
When I run `rspec spec/models/widget_spec.rb`
|
70
70
|
Then the examples should all pass
|
@@ -36,7 +36,7 @@ Feature: mock_model
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
"""
|
39
|
-
When I run
|
39
|
+
When I run `rspec spec/models/car_spec.rb`
|
40
40
|
Then the examples should all pass
|
41
41
|
|
42
42
|
Scenario: passing a string that represents an existing constant
|
@@ -51,7 +51,7 @@ Feature: mock_model
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
"""
|
54
|
-
When I run
|
54
|
+
When I run `rspec spec/models/widget_spec.rb`
|
55
55
|
Then the examples should all pass
|
56
56
|
|
57
57
|
Scenario: passing a class that does not extend ActiveModel::Naming
|
@@ -65,7 +65,7 @@ Feature: mock_model
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
"""
|
68
|
-
When I run
|
68
|
+
When I run `rspec spec/models/string_spec.rb`
|
69
69
|
Then the examples should all pass
|
70
70
|
|
71
71
|
Scenario: passing an Active Record constant
|
@@ -94,7 +94,7 @@ Feature: mock_model
|
|
94
94
|
end
|
95
95
|
end
|
96
96
|
"""
|
97
|
-
When I run
|
97
|
+
When I run `rspec spec/models/widget_spec.rb`
|
98
98
|
Then the examples should all pass
|
99
99
|
|
100
100
|
Scenario: passing an Active Record constant with method stubs
|
@@ -127,5 +127,21 @@ Feature: mock_model
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
"""
|
130
|
-
When I run
|
130
|
+
When I run `rspec spec/models/widget_spec.rb`
|
131
|
+
Then the examples should all pass
|
132
|
+
|
133
|
+
Scenario: mock_model outside rails
|
134
|
+
Given a file named "mock_model_outside_rails_spec.rb" with:
|
135
|
+
"""
|
136
|
+
require 'rspec/rails/mocks'
|
137
|
+
|
138
|
+
describe "Foo" do
|
139
|
+
it "is mockable" do
|
140
|
+
foo = mock_model("Foo")
|
141
|
+
foo.id.should eq(1001)
|
142
|
+
foo.to_param.should eq("1001")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
"""
|
146
|
+
When I run `rspec mock_model_outside_rails_spec.rb`
|
131
147
|
Then the examples should all pass
|
@@ -34,7 +34,7 @@ Feature: stub_model
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
"""
|
37
|
-
When I run
|
37
|
+
When I run `rspec spec/models/widget_spec.rb`
|
38
38
|
Then the examples should all pass
|
39
39
|
|
40
40
|
Scenario: passing an Active Record constant with a block of stubs
|
@@ -54,5 +54,5 @@ Feature: stub_model
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
"""
|
57
|
-
When I run
|
57
|
+
When I run `rspec spec/models/widget_spec.rb`
|
58
58
|
Then the examples should all pass
|
@@ -1,5 +1,10 @@
|
|
1
1
|
Feature: transactional examples
|
2
2
|
|
3
|
+
By default rspec executes each individual example in a transaction.
|
4
|
+
|
5
|
+
You can also explicitly enable/disable transactions the configuration
|
6
|
+
property 'use_transactional_examples'.
|
7
|
+
|
3
8
|
Scenario: run in transactions (default)
|
4
9
|
Given a file named "spec/models/widget_spec.rb" with:
|
5
10
|
"""
|
@@ -20,7 +25,7 @@ Feature: transactional examples
|
|
20
25
|
end
|
21
26
|
end
|
22
27
|
"""
|
23
|
-
When I run
|
28
|
+
When I run `rspec spec/models/widget_spec.rb`
|
24
29
|
Then the examples should all pass
|
25
30
|
|
26
31
|
Scenario: run in transactions (explicit)
|
@@ -47,7 +52,7 @@ Feature: transactional examples
|
|
47
52
|
end
|
48
53
|
end
|
49
54
|
"""
|
50
|
-
When I run
|
55
|
+
When I run `rspec spec/models/widget_spec.rb`
|
51
56
|
Then the examples should all pass
|
52
57
|
|
53
58
|
Scenario: disable transactions (explicit)
|
@@ -76,7 +81,7 @@ Feature: transactional examples
|
|
76
81
|
after(:all) { Widget.destroy_all }
|
77
82
|
end
|
78
83
|
"""
|
79
|
-
When I run
|
84
|
+
When I run `rspec spec/models/widget_spec.rb`
|
80
85
|
Then the examples should all pass
|
81
86
|
|
82
87
|
Scenario: run in transactions with fixture
|
@@ -84,7 +89,7 @@ Feature: transactional examples
|
|
84
89
|
"""
|
85
90
|
require "spec_helper"
|
86
91
|
|
87
|
-
describe Thing do
|
92
|
+
describe Thing do
|
88
93
|
fixtures :things
|
89
94
|
it "fixture method defined" do
|
90
95
|
things(:one)
|
@@ -96,7 +101,7 @@ Feature: transactional examples
|
|
96
101
|
one:
|
97
102
|
name: MyString
|
98
103
|
"""
|
99
|
-
When I run
|
104
|
+
When I run `rspec spec/models/thing_spec.rb`
|
100
105
|
Then the examples should all pass
|
101
106
|
|
102
107
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
Routing specs live in the `spec/routing` directory
|
1
|
+
Routing specs live in the `spec/routing` directory, or any example group with
|
2
|
+
`:type => :routing`.
|
2
3
|
|
3
4
|
Simple apps with nothing but standard RESTful routes won't get much value from
|
4
5
|
routing specs, but they can provide significant value when used to specify
|
@@ -16,7 +16,7 @@ Feature: be_routable matcher
|
|
16
16
|
end
|
17
17
|
"""
|
18
18
|
|
19
|
-
When I run
|
19
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
20
20
|
Then the output should contain "1 example, 1 failure"
|
21
21
|
|
22
22
|
Scenario: specify non-routeable route should not be routable (passes)
|
@@ -31,7 +31,7 @@ Feature: be_routable matcher
|
|
31
31
|
end
|
32
32
|
"""
|
33
33
|
|
34
|
-
When I run
|
34
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
35
35
|
Then the examples should all pass
|
36
36
|
|
37
37
|
Scenario: specify routeable route should be routable (passes)
|
@@ -46,7 +46,7 @@ Feature: be_routable matcher
|
|
46
46
|
end
|
47
47
|
"""
|
48
48
|
|
49
|
-
When I run
|
49
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
50
50
|
Then the examples should all pass
|
51
51
|
|
52
52
|
Scenario: specify non-routeable route should be routable (fails)
|
@@ -61,7 +61,7 @@ Feature: be_routable matcher
|
|
61
61
|
end
|
62
62
|
"""
|
63
63
|
|
64
|
-
When I run
|
64
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
65
65
|
Then the output should contain "1 example, 1 failure"
|
66
66
|
|
67
67
|
Scenario: be_routable in a controller spec
|
@@ -76,5 +76,5 @@ Feature: be_routable matcher
|
|
76
76
|
end
|
77
77
|
"""
|
78
78
|
|
79
|
-
When I run
|
79
|
+
When I run `rspec spec/controllers/widgets_controller_spec.rb`
|
80
80
|
Then the examples should all pass
|
@@ -1,11 +1,32 @@
|
|
1
1
|
Feature: route_to matcher
|
2
2
|
|
3
|
-
The `route_to` matcher specifies that a request (verb +
|
4
|
-
is most valuable when specifying routes other than standard RESTful
|
3
|
+
The `route_to` matcher specifies that a request (verb + path) is routable.
|
4
|
+
It is most valuable when specifying routes other than standard RESTful
|
5
|
+
routes.
|
6
|
+
|
7
|
+
get("/").should route_to("welcome#index")
|
8
|
+
|
9
|
+
or
|
5
10
|
|
6
11
|
{ :get => "/" }.should route_to(:controller => "welcome")
|
7
12
|
|
8
|
-
Scenario: passing route spec
|
13
|
+
Scenario: passing route spec with shortcut syntax
|
14
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
15
|
+
"""
|
16
|
+
require "spec_helper"
|
17
|
+
|
18
|
+
describe "routes for Widgets" do
|
19
|
+
it "routes /widgets to the widgets controller" do
|
20
|
+
get("/widgets").
|
21
|
+
should route_to("widgets#index")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
|
26
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
27
|
+
Then the examples should all pass
|
28
|
+
|
29
|
+
Scenario: passing route spec with verbose syntax
|
9
30
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
10
31
|
"""
|
11
32
|
require "spec_helper"
|
@@ -18,7 +39,7 @@ Feature: route_to matcher
|
|
18
39
|
end
|
19
40
|
"""
|
20
41
|
|
21
|
-
When I run
|
42
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
22
43
|
Then the examples should all pass
|
23
44
|
|
24
45
|
Scenario: route spec for a route that doesn't exist (fails)
|
@@ -28,11 +49,10 @@ Feature: route_to matcher
|
|
28
49
|
|
29
50
|
describe "routes for Widgets" do
|
30
51
|
it "routes /widgets/foo to the /foo action" do
|
31
|
-
|
32
|
-
should route_to(:controller => "widgets", :action => "foo")
|
52
|
+
get("/widgets/foo").should route_to("widgets#foo")
|
33
53
|
end
|
34
54
|
end
|
35
55
|
"""
|
36
56
|
|
37
|
-
When I run
|
38
|
-
Then the output should contain "1
|
57
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
58
|
+
Then the output should contain "1 failure"
|
data/features/support/env.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
-
require 'aruba'
|
1
|
+
require 'aruba/cucumber'
|
2
2
|
require 'webrat'
|
3
3
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
def run(cmd, fail_on_error=false)
|
8
|
-
if cmd =~ /^rspec/
|
9
|
-
orig_run("bundle exec #{cmd}", fail_on_error)
|
10
|
-
else
|
11
|
-
orig_run(cmd, fail_on_error)
|
12
|
-
end
|
4
|
+
module ArubaExt
|
5
|
+
def run(cmd)
|
6
|
+
super(cmd =~ /^rspec/ ? "bundle exec #{cmd}" : cmd)
|
13
7
|
end
|
14
8
|
end
|
15
9
|
|
10
|
+
World(ArubaExt)
|
11
|
+
|
16
12
|
Before do
|
17
|
-
|
13
|
+
@aruba_timeout_seconds = 10
|
18
14
|
end
|
19
15
|
|
20
16
|
unless File.directory?('./tmp/example_app')
|
@@ -41,7 +37,6 @@ def copy(file_or_dir)
|
|
41
37
|
system "cp -r #{source} #{target}"
|
42
38
|
end
|
43
39
|
|
44
|
-
|
45
40
|
Before do
|
46
41
|
steps %Q{
|
47
42
|
Given a directory named "spec"
|
@@ -56,10 +51,4 @@ Before do
|
|
56
51
|
["spec/spec_helper.rb"].each do |file_or_dir|
|
57
52
|
write_symlink("tmp/example_app/#{file_or_dir}")
|
58
53
|
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
|
-
Around do |scenario, block|
|
63
|
-
Bundler.with_clean_env &block
|
64
54
|
end
|
65
|
-
|
@@ -11,7 +11,7 @@ Feature: view spec infers controller path and action
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
"""
|
14
|
-
When I run
|
14
|
+
When I run `rspec spec/views`
|
15
15
|
Then the examples should all pass
|
16
16
|
|
17
17
|
Scenario: infer action
|
@@ -25,7 +25,7 @@ Feature: view spec infers controller path and action
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
"""
|
28
|
-
When I run
|
28
|
+
When I run `rspec spec/views`
|
29
29
|
Then the examples should all pass
|
30
30
|
|
31
31
|
Scenario: do not infer action in a partial
|
@@ -39,6 +39,6 @@ Feature: view spec infers controller path and action
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
"""
|
42
|
-
When I run
|
42
|
+
When I run `rspec spec/views`
|
43
43
|
Then the examples should all pass
|
44
44
|
|
@@ -26,7 +26,7 @@ Feature: stub template
|
|
26
26
|
"""
|
27
27
|
<%= render :partial => "gadget", :collection => @gadgets %>
|
28
28
|
"""
|
29
|
-
When I run
|
29
|
+
When I run `rspec spec/views/gadgets/list.html.erb_spec.rb`
|
30
30
|
Then the examples should all pass
|
31
31
|
|
32
32
|
Scenario: stub template that exists
|
@@ -46,6 +46,6 @@ Feature: stub template
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
"""
|
49
|
-
When I run
|
49
|
+
When I run `rspec spec/views/gadgets/edit.html.erb_spec.rb`
|
50
50
|
Then the examples should all pass
|
51
51
|
|
@@ -21,7 +21,7 @@ Feature: view spec
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
"""
|
24
|
-
When I run
|
24
|
+
When I run `rspec spec/views`
|
25
25
|
Then the examples should all pass
|
26
26
|
|
27
27
|
Scenario: passing spec with before and nesting
|
@@ -48,7 +48,7 @@ Feature: view spec
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
"""
|
51
|
-
When I run
|
51
|
+
When I run `rspec spec/views`
|
52
52
|
Then the examples should all pass
|
53
53
|
|
54
54
|
Scenario: passing spec with explicit template rendering
|
@@ -70,7 +70,7 @@ Feature: view spec
|
|
70
70
|
"""
|
71
71
|
<h2><%= @widget.name %></h2>
|
72
72
|
"""
|
73
|
-
When I run
|
73
|
+
When I run `rspec spec/views`
|
74
74
|
Then the examples should all pass
|
75
75
|
|
76
76
|
Scenario: passing spec with rendering of locals in a partial
|
@@ -92,7 +92,7 @@ Feature: view spec
|
|
92
92
|
"""
|
93
93
|
<h3><%= widget.name %></h3>
|
94
94
|
"""
|
95
|
-
When I run
|
95
|
+
When I run `rspec spec/views`
|
96
96
|
Then the examples should all pass
|
97
97
|
|
98
98
|
Scenario: passing spec with rendering of locals in an implicit partial
|
@@ -114,7 +114,7 @@ Feature: view spec
|
|
114
114
|
"""
|
115
115
|
<h3><%= widget.name %></h3>
|
116
116
|
"""
|
117
|
-
When I run
|
117
|
+
When I run `rspec spec/views`
|
118
118
|
Then the examples should all pass
|
119
119
|
|
120
120
|
Scenario: passing spec with rendering of text
|
@@ -131,7 +131,7 @@ Feature: view spec
|
|
131
131
|
end
|
132
132
|
end
|
133
133
|
"""
|
134
|
-
When I run
|
134
|
+
When I run `rspec spec/views`
|
135
135
|
Then the examples should all pass
|
136
136
|
|
137
137
|
Scenario: passing spec with rendering of Prototype helper update
|
@@ -150,7 +150,7 @@ Feature: view spec
|
|
150
150
|
end
|
151
151
|
end
|
152
152
|
"""
|
153
|
-
When I run
|
153
|
+
When I run `rspec spec/views`
|
154
154
|
Then the examples should all pass
|
155
155
|
|
156
156
|
Scenario: spec with view that accesses helper_method helpers
|
@@ -181,5 +181,5 @@ Feature: view spec
|
|
181
181
|
end
|
182
182
|
end
|
183
183
|
"""
|
184
|
-
When I run
|
184
|
+
When I run `rspec spec/views/secrets`
|
185
185
|
Then the examples should all pass
|