rspec-rails 2.4.1 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile-3-0-stable +6 -0
  3. data/Gemfile-3.0.0 +3 -0
  4. data/Gemfile-3.0.3 +3 -0
  5. data/{Gemfile → Gemfile-base} +4 -8
  6. data/Gemfile-master +5 -0
  7. data/History.md +1 -114
  8. data/README.md +2 -2
  9. data/Rakefile +9 -7
  10. data/Thorfile +7 -0
  11. data/Upgrade.md +1 -63
  12. data/features/.nav +5 -4
  13. data/features/Autotest.md +15 -8
  14. data/features/Changelog.md +127 -0
  15. data/features/Upgrade.md +60 -0
  16. data/features/controller_specs/README.md +3 -2
  17. data/features/controller_specs/anonymous_controller.feature +2 -2
  18. data/features/controller_specs/isolation_from_views.feature +2 -2
  19. data/features/controller_specs/render_views.feature +42 -60
  20. data/features/helper_specs/helper_spec.feature +3 -3
  21. data/features/mailer_specs/url_helpers.feature +2 -2
  22. data/features/matchers/new_record_matcher.feature +2 -2
  23. data/features/matchers/redirect_to_matcher.feature +1 -1
  24. data/features/matchers/render_template_matcher.feature +1 -1
  25. data/features/mocks/mock_model.feature +5 -5
  26. data/features/mocks/stub_model.feature +2 -2
  27. data/features/model_specs/errors_on.feature +1 -1
  28. data/features/model_specs/transactional_examples.feature +4 -4
  29. data/features/routing_specs/be_routable_matcher.feature +3 -3
  30. data/features/routing_specs/named_routes.feature +1 -1
  31. data/features/routing_specs/route_to_matcher.feature +1 -1
  32. data/features/step_definitions/{rspec_steps.rb → additional_cli_steps.rb} +1 -2
  33. data/features/view_specs/inferred_controller_path.feature +3 -3
  34. data/features/view_specs/stub_template.feature +2 -2
  35. data/features/view_specs/view_spec.feature +8 -8
  36. data/lib/generators/rspec/integration/templates/request_spec.rb +2 -2
  37. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +1 -1
  38. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  39. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
  40. data/lib/rspec/rails/example.rb +5 -3
  41. data/lib/rspec/rails/example/controller_example_group.rb +10 -6
  42. data/lib/rspec/rails/example/request_example_group.rb +1 -1
  43. data/lib/rspec/rails/mocks.rb +6 -0
  44. data/lib/rspec/rails/version.rb +1 -1
  45. data/lib/rspec/rails/view_rendering.rb +1 -1
  46. data/spec/rspec/rails/mocks/ar_classes.rb +13 -25
  47. data/spec/rspec/rails/mocks/mock_model_spec.rb +6 -0
  48. data/spec/rspec/rails/mocks/stub_model_spec.rb +9 -4
  49. data/spec/rspec/rails/view_rendering_spec.rb +7 -1
  50. data/templates/Gemfile-base +17 -0
  51. metadata +21 -15
  52. data/templates/Gemfile +0 -15
@@ -32,7 +32,7 @@ Feature: be_routable matcher
32
32
  """
33
33
 
34
34
  When I run "rspec spec/routing/widgets_routing_spec.rb"
35
- Then the output should contain "1 example, 0 failures"
35
+ Then the examples should all pass
36
36
 
37
37
  Scenario: specify routeable route should be routable (passes)
38
38
  Given a file named "spec/routing/widgets_routing_spec.rb" with:
@@ -47,7 +47,7 @@ Feature: be_routable matcher
47
47
  """
48
48
 
49
49
  When I run "rspec spec/routing/widgets_routing_spec.rb"
50
- Then the output should contain "1 example, 0 failures"
50
+ Then the examples should all pass
51
51
 
52
52
  Scenario: specify non-routeable route should be routable (fails)
53
53
  Given a file named "spec/routing/widgets_routing_spec.rb" with:
@@ -77,4 +77,4 @@ Feature: be_routable matcher
77
77
  """
78
78
 
79
79
  When I run "rspec spec/controllers/widgets_controller_spec.rb"
80
- Then the output should contain "1 example, 0 failures"
80
+ Then the examples should all pass
@@ -15,4 +15,4 @@ Feature: named routes
15
15
  end
16
16
  """
17
17
  When I run "rspec spec"
18
- Then the output should contain "1 example, 0 failures"
18
+ Then the examples should all pass
@@ -19,7 +19,7 @@ Feature: route_to matcher
19
19
  """
20
20
 
21
21
  When I run "rspec spec/routing/widgets_routing_spec.rb"
22
- Then the output should contain "1 example, 0 failures"
22
+ Then the examples should all pass
23
23
 
24
24
  Scenario: route spec for a route that doesn't exist (fails)
25
25
  Given a file named "spec/routing/widgets_routing_spec.rb" with:
@@ -1,5 +1,4 @@
1
- Then /^the example(s)? should( all)? pass$/ do |_,_|
1
+ Then /^the example(s)? should( all)? pass$/ do |_, _|
2
2
  Then %q{the exit status should be 0}
3
3
  Then %q{the output should contain "0 failures"}
4
4
  end
5
-
@@ -12,7 +12,7 @@ Feature: view spec infers controller path and action
12
12
  end
13
13
  """
14
14
  When I run "rspec spec/views"
15
- Then the output should contain "1 example, 0 failures"
15
+ Then the examples should all pass
16
16
 
17
17
  Scenario: infer action
18
18
  Given a file named "spec/views/widgets/new.html.erb_spec.rb" with:
@@ -26,7 +26,7 @@ Feature: view spec infers controller path and action
26
26
  end
27
27
  """
28
28
  When I run "rspec spec/views"
29
- Then the output should contain "1 example, 0 failures"
29
+ Then the examples should all pass
30
30
 
31
31
  Scenario: do not infer action in a partial
32
32
  Given a file named "spec/views/widgets/_form.html.erb_spec.rb" with:
@@ -40,5 +40,5 @@ Feature: view spec infers controller path and action
40
40
  end
41
41
  """
42
42
  When I run "rspec spec/views"
43
- Then the output should contain "1 example, 0 failures"
43
+ Then the examples should all pass
44
44
 
@@ -27,7 +27,7 @@ Feature: stub template
27
27
  <%= render :partial => "gadget", :collection => @gadgets %>
28
28
  """
29
29
  When I run "rspec spec/views/gadgets/list.html.erb_spec.rb"
30
- Then the output should contain "1 example, 0 failures"
30
+ Then the examples should all pass
31
31
 
32
32
  Scenario: stub template that exists
33
33
  Given a file named "spec/views/gadgets/edit.html.erb_spec.rb" with:
@@ -47,5 +47,5 @@ Feature: stub template
47
47
  end
48
48
  """
49
49
  When I run "rspec spec/views/gadgets/edit.html.erb_spec.rb"
50
- Then the output should contain "1 example, 0 failures"
50
+ Then the examples should all pass
51
51
 
@@ -22,7 +22,7 @@ Feature: view spec
22
22
  end
23
23
  """
24
24
  When I run "rspec spec/views"
25
- Then the output should contain "1 example, 0 failures"
25
+ Then the examples should all pass
26
26
 
27
27
  Scenario: passing spec with before and nesting
28
28
  Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
@@ -49,7 +49,7 @@ Feature: view spec
49
49
  end
50
50
  """
51
51
  When I run "rspec spec/views"
52
- Then the output should contain "1 example, 0 failures"
52
+ Then the examples should all pass
53
53
 
54
54
  Scenario: passing spec with explicit template rendering
55
55
  Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
@@ -71,7 +71,7 @@ Feature: view spec
71
71
  <h2><%= @widget.name %></h2>
72
72
  """
73
73
  When I run "rspec spec/views"
74
- Then the output should contain "1 example, 0 failures"
74
+ Then the examples should all pass
75
75
 
76
76
  Scenario: passing spec with rendering of locals in a partial
77
77
  Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
@@ -93,7 +93,7 @@ Feature: view spec
93
93
  <h3><%= widget.name %></h3>
94
94
  """
95
95
  When I run "rspec spec/views"
96
- Then the output should contain "1 example, 0 failures"
96
+ Then the examples should all pass
97
97
 
98
98
  Scenario: passing spec with rendering of locals in an implicit partial
99
99
  Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
@@ -115,7 +115,7 @@ Feature: view spec
115
115
  <h3><%= widget.name %></h3>
116
116
  """
117
117
  When I run "rspec spec/views"
118
- Then the output should contain "1 example, 0 failures"
118
+ Then the examples should all pass
119
119
 
120
120
  Scenario: passing spec with rendering of text
121
121
  Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with:
@@ -132,7 +132,7 @@ Feature: view spec
132
132
  end
133
133
  """
134
134
  When I run "rspec spec/views"
135
- Then the output should contain "1 example, 0 failures"
135
+ Then the examples should all pass
136
136
 
137
137
  Scenario: passing spec with rendering of Prototype helper update
138
138
  Given a file named "spec/views/widgets/prototype_update.html.erb_spec.rb" with:
@@ -151,7 +151,7 @@ Feature: view spec
151
151
  end
152
152
  """
153
153
  When I run "rspec spec/views"
154
- Then the output should contain "1 example, 0 failures"
154
+ Then the examples should all pass
155
155
 
156
156
  Scenario: spec with view that accesses helper_method helpers
157
157
  Given a file named "app/views/secrets/index.html.erb" with:
@@ -182,4 +182,4 @@ Feature: view spec
182
182
  end
183
183
  """
184
184
  When I run "rspec spec/views/secrets"
185
- Then the output should contain "1 example, 0 failures"
185
+ Then the examples should all pass
@@ -4,10 +4,10 @@ describe "<%= class_name.pluralize %>" do
4
4
  describe "GET /<%= table_name %>" do
5
5
  it "works! (now write some real specs)" do
6
6
  <% if webrat? -%>
7
- visit <%= table_name %>_path
7
+ visit <%= index_helper %>_path
8
8
  <% else -%>
9
9
  # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
10
- get <%= table_name %>_path
10
+ get <%= index_helper %>_path
11
11
  <% end -%>
12
12
  response.status.should be(200)
13
13
  end
@@ -120,7 +120,7 @@ describe <%= controller_class_name %>Controller do
120
120
  it "redirects to the <%= table_name %> list" do
121
121
  <%= stub orm_class.find(class_name) %> { <%= mock_file_name %> }
122
122
  delete :destroy, :id => "1"
123
- response.should redirect_to(<%= table_name %>_url)
123
+ response.should redirect_to(<%= index_helper %>_url)
124
124
  end
125
125
  end
126
126
 
@@ -21,7 +21,7 @@ describe "<%= table_name %>/edit.html.<%= options[:template_engine] %>" do
21
21
  end
22
22
  <% else -%>
23
23
  # Run the generator again with the --webrat flag if you want to use webrat matchers
24
- assert_select "form", :action => <%= file_name %>_path(@<%= file_name %>), :method => "post" do
24
+ assert_select "form", :action => <%= index_helper %>_path(@<%= file_name %>), :method => "post" do
25
25
  <% for attribute in output_attributes -%>
26
26
  assert_select "<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]"
27
27
  <% end -%>
@@ -20,7 +20,7 @@ describe "<%= table_name %>/new.html.<%= options[:template_engine] %>" do
20
20
  end
21
21
  <% else -%>
22
22
  # Run the generator again with the --webrat flag if you want to use webrat matchers
23
- assert_select "form", :action => <%= table_name %>_path, :method => "post" do
23
+ assert_select "form", :action => <%= index_helper %>_path, :method => "post" do
24
24
  <% for attribute in output_attributes -%>
25
25
  assert_select "<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]"
26
26
  <% end -%>
@@ -18,9 +18,11 @@ RSpec::configure do |c|
18
18
  c.include RSpec::Rails::HelperExampleGroup, :type => :helper, :example_group => {
19
19
  :file_path => c.escaped_path(%w[spec helpers])
20
20
  }
21
- c.include RSpec::Rails::MailerExampleGroup, :type => :mailer, :example_group => {
22
- :file_path => c.escaped_path(%w[spec mailers])
23
- }
21
+ if defined?(RSpec::Rails::MailerExampleGroup)
22
+ c.include RSpec::Rails::MailerExampleGroup, :type => :mailer, :example_group => {
23
+ :file_path => c.escaped_path(%w[spec mailers])
24
+ }
25
+ end
24
26
  c.include RSpec::Rails::ModelExampleGroup, :type => :model, :example_group => {
25
27
  :file_path => c.escaped_path(%w[spec models])
26
28
  }
@@ -56,15 +56,19 @@ module RSpec::Rails
56
56
  #
57
57
  # RSpec's preferred approach to spec'ing controller behaviour is to isolate
58
58
  # the controller from its collaborators. By default, therefore, controller
59
- # example groups do not render views. This means that a view template need
60
- # not even exist in order to run a controller spec, and you can still specify
61
- # which template the controller should render.
59
+ # example groups do not render the views in your app. Due to the way Rails
60
+ # searches for view templates, the template still needs to exist, but it
61
+ # won't actually be loaded.
62
+ #
63
+ # NOTE that this is different from rspec-rails-1 with rails-2, which did not
64
+ # require the presence of the file at all. Due to changes in rails-3, this
65
+ # was no longer feasible in rspec-rails-2.
62
66
  #
63
67
  # == View rendering
64
68
  #
65
- # If you prefer a more integrated approach, similar to that of
66
- # Rails' functional tests, you can tell controller groups to
67
- # render views with the +render_views+ declaration:
69
+ # If you prefer a more integrated approach, similar to that of Rails'
70
+ # functional tests, you can tell controller groups to render the views in the
71
+ # app with the +render_views+ declaration:
68
72
  #
69
73
  # describe WidgetsController do
70
74
  # render_views
@@ -48,7 +48,7 @@ module RSpec::Rails
48
48
  metadata[:type] = :request
49
49
 
50
50
  before do
51
- @router = ::Rails.application.routes
51
+ @routes = ::Rails.application.routes
52
52
  end
53
53
 
54
54
  webrat do
@@ -27,6 +27,10 @@ module RSpec
27
27
  self.stub(:id) { nil }
28
28
  end
29
29
 
30
+ def [](key)
31
+ send(key)
32
+ end
33
+
30
34
  def new_record?
31
35
  !persisted?
32
36
  end
@@ -77,6 +81,7 @@ EOM
77
81
  stubs = stubs.reverse_merge(:persisted? => !!stubs[:id])
78
82
  stubs = stubs.reverse_merge(:destroyed? => false)
79
83
  stubs = stubs.reverse_merge(:marked_for_destruction? => false)
84
+ stubs = stubs.reverse_merge(:blank? => false)
80
85
 
81
86
  mock("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m|
82
87
  m.extend ActiveModelInstanceMethods
@@ -188,6 +193,7 @@ EOM
188
193
  stubs = stubs.reverse_merge(:id => next_id)
189
194
  stubs = stubs.reverse_merge(:persisted? => !!stubs[:id])
190
195
  end
196
+ stubs = stubs.reverse_merge(:blank? => false)
191
197
  stubs.each do |k,v|
192
198
  m.__send__("#{k}=", stubs.delete(k)) if m.respond_to?("#{k}=")
193
199
  end
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Rails # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.4.1'
4
+ STRING = '2.5.0'
5
5
  end
6
6
  end
7
7
  end
@@ -23,7 +23,7 @@ module RSpec
23
23
 
24
24
  module ClassMethods
25
25
  def metadata_for_rspec_rails
26
- metadata[:rspec_rails] ||= {}
26
+ metadata[:rspec_rails] = metadata[:rspec_rails] ? metadata[:rspec_rails].dup : {}
27
27
  end
28
28
 
29
29
  # See RSpec::Rails::ControllerExampleGroup
@@ -1,14 +1,13 @@
1
- module NoConnections
2
- def self.included(mod)
3
- (class << mod; self; end).class_eval do
4
- def columns
5
- []
6
- end
7
-
8
- def connection
9
- RSpec::Mocks::Mock.new.as_null_object
10
- end
11
- end
1
+ module Connections
2
+ def self.extended(host)
3
+ host.establish_connection :adapter => 'sqlite3',
4
+ :database => ':memory:'
5
+
6
+ host.connection.execute <<-eosql
7
+ CREATE TABLE #{host.table_name} (
8
+ #{host.primary_key} integer PRIMARY KEY AUTOINCREMENT
9
+ )
10
+ eosql
12
11
  end
13
12
  end
14
13
 
@@ -18,7 +17,7 @@ class NonActiveRecordModel
18
17
  end
19
18
 
20
19
  class MockableModel < ActiveRecord::Base
21
- include NoConnections
20
+ extend Connections
22
21
  has_one :associated_model
23
22
  end
24
23
 
@@ -26,23 +25,12 @@ class SubMockableModel < MockableModel
26
25
  end
27
26
 
28
27
  class AssociatedModel < ActiveRecord::Base
29
- include NoConnections
28
+ extend Connections
30
29
  belongs_to :mockable_model
31
30
  end
32
31
 
33
32
  class AlternatePrimaryKeyModel < ActiveRecord::Base
34
- include NoConnections
35
33
  self.primary_key = :my_id
34
+ extend Connections
36
35
  attr_accessor :my_id
37
36
  end
38
-
39
- class ConnectableModel < ActiveRecord::Base
40
- establish_connection :adapter => 'sqlite3',
41
- :database => ':memory:'
42
-
43
- connection.execute <<-eosql
44
- CREATE TABLE connectable_models (
45
- id integer PRIMARY KEY AUTOINCREMENT
46
- )
47
- eosql
48
- end
@@ -260,6 +260,12 @@ describe "mock_model(RealModel)" do
260
260
  end
261
261
  end
262
262
 
263
+ describe "#blank?" do
264
+ it "is false" do
265
+ mock_model(MockableModel).should_not be_blank
266
+ end
267
+ end
268
+
263
269
  describe "ActiveModel Lint tests" do
264
270
  require 'test/unit/assertions'
265
271
  require 'active_model/lint'
@@ -35,6 +35,11 @@ describe "stub_model" do
35
35
  second.to_param.to_i.should == (first.to_param.to_i + 1)
36
36
  end
37
37
 
38
+ describe "#blank?" do
39
+ it "is false" do
40
+ stub_model(model_class).should_not be_blank
41
+ end
42
+ end
38
43
  end
39
44
 
40
45
  context "with ActiveModel (not ActiveRecord)" do
@@ -84,7 +89,7 @@ describe "stub_model" do
84
89
 
85
90
  it "raises when hitting the db" do
86
91
  lambda do
87
- stub_model(ConnectableModel).connection
92
+ stub_model(MockableModel).connection
88
93
  end.should raise_error(RSpec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
89
94
  end
90
95
 
@@ -108,7 +113,7 @@ describe "stub_model" do
108
113
 
109
114
  describe "alternate primary key" do
110
115
  it "has the correct primary_key name" do
111
- stub_model(AlternatePrimaryKeyModel).class.primary_key.should eql('my_id')
116
+ stub_model(AlternatePrimaryKeyModel).class.primary_key.to_s.should eql('my_id')
112
117
  end
113
118
 
114
119
  it "has a primary_key" do
@@ -138,11 +143,11 @@ describe "stub_model" do
138
143
  end
139
144
 
140
145
  it "passes associated_model == mock" do
141
- @stub_model.should == @real.mockable_model
146
+ @stub_model.should == @real.mockable_model
142
147
  end
143
148
 
144
149
  it "passes mock == associated_model" do
145
- @real.mockable_model.should == @stub_model
150
+ @real.mockable_model.should == @stub_model
146
151
  end
147
152
  end
148
153
 
@@ -88,7 +88,13 @@ module RSpec::Rails
88
88
  end
89
89
  end
90
90
 
91
- it "overrides the parent group" do
91
+ it "leaves the parent group as/is" do
92
+ group.render_views
93
+ nested_group.render_views false
94
+ group.new.render_views?.should be_true
95
+ end
96
+
97
+ it "overrides the value inherited from the parent group" do
92
98
  group.render_views
93
99
  nested_group.render_views false
94
100
  nested_group.new.render_views?.should be_false
@@ -0,0 +1,17 @@
1
+ source 'http://rubygems.org'
2
+
3
+ group :development, :test do
4
+ %w[rspec rspec-core rspec-expectations rspec-mocks rspec-rails].each do |lib|
5
+ library_path = File.expand_path("../../../../#{lib}", __FILE__)
6
+ if File.exist?(library_path)
7
+ gem lib, :path => library_path
8
+ else
9
+ gem lib
10
+ end
11
+ end
12
+ gem "rcov"
13
+ gem "webrat", "0.7.2"
14
+ gem "ZenTest", "4.4.2"
15
+ end
16
+
17
+ gem 'sqlite3-ruby', :require => 'sqlite3'