rspec-rails 2.5.0 → 2.6.0

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 (90) hide show
  1. data/.gitignore +10 -5
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/README.md +2 -0
  5. data/README_DEV.md +43 -0
  6. data/Rakefile +72 -31
  7. data/Thorfile +33 -18
  8. data/features/.nav +2 -0
  9. data/features/Autotest.md +7 -0
  10. data/features/Changelog.md +26 -2
  11. data/features/Generators.md +1 -1
  12. data/features/GettingStarted.md +45 -1
  13. data/features/Upgrade.md +13 -12
  14. data/features/controller_specs/README.md +18 -10
  15. data/features/controller_specs/anonymous_controller.feature +5 -5
  16. data/features/controller_specs/controller_spec.feature +1 -2
  17. data/features/controller_specs/isolation_from_views.feature +49 -3
  18. data/features/controller_specs/render_views.feature +3 -3
  19. data/features/helper_specs/helper_spec.feature +3 -3
  20. data/features/mailer_specs/url_helpers.feature +2 -2
  21. data/features/matchers/new_record_matcher.feature +1 -43
  22. data/features/matchers/redirect_to_matcher.feature +3 -3
  23. data/features/matchers/render_template_matcher.feature +12 -9
  24. data/features/mocks/mock_model.feature +21 -5
  25. data/features/mocks/stub_model.feature +2 -2
  26. data/features/model_specs/errors_on.feature +1 -1
  27. data/features/model_specs/transactional_examples.feature +10 -5
  28. data/features/request_specs/request_spec.feature +49 -0
  29. data/features/routing_specs/README.md +2 -1
  30. data/features/routing_specs/be_routable_matcher.feature +5 -5
  31. data/features/routing_specs/named_routes.feature +1 -1
  32. data/features/routing_specs/route_to_matcher.feature +28 -8
  33. data/features/step_definitions/additional_cli_steps.rb +1 -1
  34. data/features/support/env.rb +7 -19
  35. data/features/view_specs/inferred_controller_path.feature +3 -3
  36. data/features/view_specs/stub_template.feature +2 -2
  37. data/features/view_specs/view_spec.feature +16 -35
  38. data/gemfiles/.bundle/config +2 -0
  39. data/gemfiles/base.rb +58 -0
  40. data/gemfiles/rails-3-0-stable +6 -0
  41. data/gemfiles/rails-3.0.0 +5 -0
  42. data/gemfiles/rails-3.0.1 +5 -0
  43. data/gemfiles/rails-3.0.2 +5 -0
  44. data/gemfiles/rails-3.0.3 +5 -0
  45. data/gemfiles/rails-3.0.4 +5 -0
  46. data/gemfiles/rails-3.0.5 +5 -0
  47. data/gemfiles/rails-3.0.6 +5 -0
  48. data/gemfiles/rails-3.0.7 +5 -0
  49. data/gemfiles/rails-3.1.0.beta1 +5 -0
  50. data/gemfiles/rails-master +7 -0
  51. data/lib/generators/rspec/scaffold/scaffold_generator.rb +20 -2
  52. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +86 -54
  53. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +7 -7
  54. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  55. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -5
  56. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
  57. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  58. data/lib/rspec/rails/example/controller_example_group.rb +12 -22
  59. data/lib/rspec/rails/example/helper_example_group.rb +0 -5
  60. data/lib/rspec/rails/example/mailer_example_group.rb +0 -9
  61. data/lib/rspec/rails/example/request_example_group.rb +0 -25
  62. data/lib/rspec/rails/example/routing_example_group.rb +1 -0
  63. data/lib/rspec/rails/example/view_example_group.rb +7 -6
  64. data/lib/rspec/rails/matchers/routing_matchers.rb +23 -2
  65. data/lib/rspec/rails/mocks.rb +3 -0
  66. data/lib/rspec/rails/tasks/rspec.rake +1 -1
  67. data/lib/rspec/rails/vendor/capybara.rb +29 -0
  68. data/lib/rspec/rails/vendor/webrat.rb +33 -0
  69. data/lib/rspec/rails/version.rb +1 -1
  70. data/lib/rspec/rails/view_rendering.rb +24 -8
  71. data/lib/rspec/rails.rb +2 -2
  72. data/rspec-rails.gemspec +5 -36
  73. data/spec/autotest/rails_rspec2_spec.rb +2 -7
  74. data/spec/rspec/rails/example/controller_example_group_spec.rb +25 -0
  75. data/spec/rspec/rails/matchers/route_to_spec.rb +15 -0
  76. data/spec/rspec/rails/mocks/ar_classes.rb +5 -2
  77. data/spec/rspec/rails/view_rendering_spec.rb +0 -6
  78. data/spec/spec_helper.rb +0 -22
  79. data/spec/support/matchers.rb +9 -0
  80. data/templates/generate_stuff.rb +9 -1
  81. data/templates/run_specs.rb +2 -2
  82. metadata +44 -65
  83. data/Gemfile-3-0-stable +0 -6
  84. data/Gemfile-3.0.0 +0 -3
  85. data/Gemfile-3.0.3 +0 -3
  86. data/Gemfile-base +0 -38
  87. data/Gemfile-master +0 -5
  88. data/lib/rspec/rails/browser_simulators.rb +0 -30
  89. data/specs.watchr +0 -59
  90. data/templates/Gemfile-base +0 -17
@@ -16,12 +16,12 @@ Feature: view spec
16
16
 
17
17
  render
18
18
 
19
- rendered.should contain("slicer")
20
- rendered.should contain("dicer")
19
+ rendered.should =~ /slicer/
20
+ rendered.should =~ /dicer/
21
21
  end
22
22
  end
23
23
  """
24
- When I run "rspec spec/views"
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
@@ -42,13 +42,13 @@ Feature: view spec
42
42
  it "displays both widgets" do
43
43
  render
44
44
 
45
- rendered.should contain("slicer")
46
- rendered.should contain("dicer")
45
+ rendered.should =~ /slicer/
46
+ rendered.should =~ /dicer/
47
47
  end
48
48
  end
49
49
  end
50
50
  """
51
- When I run "rspec spec/views"
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
@@ -62,7 +62,7 @@ Feature: view spec
62
62
 
63
63
  render :template => "widgets/widget.html.erb"
64
64
 
65
- rendered.should contain("slicer")
65
+ rendered.should =~ /slicer/
66
66
  end
67
67
  end
68
68
  """
@@ -70,7 +70,7 @@ Feature: view spec
70
70
  """
71
71
  <h2><%= @widget.name %></h2>
72
72
  """
73
- When I run "rspec spec/views"
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
@@ -84,7 +84,7 @@ Feature: view spec
84
84
 
85
85
  render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
86
86
 
87
- rendered.should contain("slicer")
87
+ rendered.should =~ /slicer/
88
88
  end
89
89
  end
90
90
  """
@@ -92,7 +92,7 @@ Feature: view spec
92
92
  """
93
93
  <h3><%= widget.name %></h3>
94
94
  """
95
- When I run "rspec spec/views"
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
@@ -106,7 +106,7 @@ Feature: view spec
106
106
 
107
107
  render "widgets/widget", :widget => widget
108
108
 
109
- rendered.should contain("slicer")
109
+ rendered.should =~ /slicer/
110
110
  end
111
111
  end
112
112
  """
@@ -114,7 +114,7 @@ Feature: view spec
114
114
  """
115
115
  <h3><%= widget.name %></h3>
116
116
  """
117
- When I run "rspec spec/views"
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
@@ -127,30 +127,11 @@ Feature: view spec
127
127
 
128
128
  render :text => "This is directly rendered"
129
129
 
130
- rendered.should contain("directly rendered")
130
+ rendered.should =~ /directly rendered/
131
131
  end
132
132
  end
133
133
  """
134
- When I run "rspec spec/views"
135
- Then the examples should all pass
136
-
137
- Scenario: passing spec with rendering of Prototype helper update
138
- Given a file named "spec/views/widgets/prototype_update.html.erb_spec.rb" with:
139
- """
140
- require "spec_helper"
141
-
142
- describe "render a Prototype helper update" do
143
- it "hides the status indicator" do
144
-
145
- render :update do |page|
146
- page.hide 'status-indicator'
147
- end
148
-
149
- rendered.should contain("Element.hide(\"status-indicator\")")
150
- end
151
- end
152
- """
153
- When I run "rspec spec/views"
134
+ When I run `rspec spec/views`
154
135
  Then the examples should all pass
155
136
 
156
137
  Scenario: spec with view that accesses helper_method helpers
@@ -177,9 +158,9 @@ Feature: view spec
177
158
 
178
159
  it 'checks for admin access' do
179
160
  render
180
- rendered.should contain('Secret admin area')
161
+ rendered.should =~ /Secret admin area/
181
162
  end
182
163
  end
183
164
  """
184
- When I run "rspec spec/views/secrets"
165
+ When I run `rspec spec/views/secrets`
185
166
  Then the examples should all pass
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_BIN: bin
data/gemfiles/base.rb ADDED
@@ -0,0 +1,58 @@
1
+ module GemfileBase
2
+ def self.extended(host)
3
+ host.instance_eval do
4
+ source "http://rubygems.org"
5
+
6
+ %w[rspec rspec-core rspec-expectations rspec-mocks rspec-rails].each do |lib|
7
+ library_path = File.expand_path("../../../#{lib}", __FILE__)
8
+ if File.exist?(library_path)
9
+ gem lib, :path => library_path
10
+ elsif ENV["CI"] || ENV["USE_GIT_REPOS"]
11
+ gem lib, :git => "git://github.com/rspec/#{lib}.git"
12
+ else
13
+ gem lib
14
+ end
15
+ end
16
+
17
+ gem 'sqlite3-ruby', :require => 'sqlite3'
18
+ gem "cucumber", "~> 0.10.2"
19
+ gem "aruba", "~> 0.3.6"
20
+ gem "growl", "1.0.3"
21
+ gem "ZenTest", "~> 4.4.2"
22
+
23
+ # gem "webrat", "0.7.3"
24
+ # gem "capybara", "~> 0.4"
25
+ # gem "capybara", "1.0.0.beta1"
26
+
27
+ unless ENV['CI']
28
+ gem "rcov", "0.9.9"
29
+ gem "relish", "0.2.0"
30
+ gem "guard-rspec", "0.1.9"
31
+
32
+ if RUBY_PLATFORM =~ /darwin/
33
+ gem "autotest-fsevent", "~> 0.2.4"
34
+ gem "autotest-growl", "~> 0.2.9"
35
+ end
36
+
37
+ platforms :mri_18 do
38
+ gem 'ruby-debug'
39
+ end
40
+
41
+ platforms :mri_19 do
42
+ gem 'linecache19', '0.5.11' # 0.5.12 cannot install on 1.9.1, and 0.5.11 appears to work with both 1.9.1 & 1.9.2
43
+ gem 'ruby-debug19'
44
+ gem 'ruby-debug-base19', RUBY_VERSION == '1.9.1' ? '0.11.23' : '~> 0.11.24'
45
+ end
46
+
47
+ platforms :ruby_18, :ruby_19 do
48
+ gem "rb-fsevent", "~> 0.3.9"
49
+ gem "ruby-prof", "~> 0.9.2"
50
+ end
51
+ end
52
+
53
+ platforms :jruby do
54
+ gem "jruby-openssl"
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", :git => "git://github.com/rails/rails.git", :branch => "3-0-stable"
6
+ gem "arel", :git => "git://github.com/rails/arel.git", :branch => "2-0-stable"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.0"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.1"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.2"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.3"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.4"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.5"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.6"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.0.7"
@@ -0,0 +1,5 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", "3.1.0.beta1"
@@ -0,0 +1,7 @@
1
+ require File.expand_path("../base.rb", __FILE__)
2
+
3
+ extend GemfileBase
4
+
5
+ gem "rails", :git => "git://github.com/rails/rails.git"
6
+ gem "arel", :git => "git://github.com/rails/arel.git"
7
+ gem "rack", :git => "git://github.com/rack/rack.git"
@@ -65,6 +65,24 @@ module Rspec
65
65
  "{'these' => 'params'}"
66
66
  end
67
67
 
68
+ # support for namespaced-resources
69
+ def ns_file_name
70
+ if ARGV[0].match(/(\w+)\/(\w+)/)
71
+ "#{$1.underscore}_#{$2.singularize.underscore}"
72
+ else
73
+ file_name
74
+ end
75
+ end
76
+
77
+ # support for namespaced-resources
78
+ def ns_table_name
79
+ if ARGV[0].match(/(\w+)\/(\w+)/)
80
+ "#{$1.underscore}/#{$2.tableize}"
81
+ else
82
+ table_name
83
+ end
84
+ end
85
+
68
86
  # Returns the name of the mock. For example, if the file name is user,
69
87
  # it returns mock_user.
70
88
  #
@@ -81,9 +99,9 @@ module Rspec
81
99
  if hash
82
100
  method, and_return = hash.to_a.first
83
101
  method = orm_instance.send(method).split('.').last.gsub(/\(.*?\)/, '')
84
- "mock_#{file_name}(:#{method} => #{and_return})"
102
+ "mock_#{ns_file_name}(:#{method} => #{and_return})"
85
103
  else
86
- "mock_#{file_name}"
104
+ "mock_#{ns_file_name}"
87
105
  end
88
106
  end
89
107
 
@@ -2,73 +2,96 @@ require 'spec_helper'
2
2
 
3
3
  # This spec was generated by rspec-rails when you ran the scaffold generator.
4
4
  # It demonstrates how one might use RSpec to specify the controller code that
5
- # was generated by the Rails when you ran the scaffold generator.
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+ #
15
+ # Compared to earlier versions of this generator, there is very limited use of
16
+ # stubs and message expectations in this spec. Stubs are only used when there
17
+ # is no simpler way to get a handle on the object needed for the example.
18
+ # Message expectations are only used when there is no simpler way to specify
19
+ # that an instance is receiving a specific message.
6
20
 
7
21
  describe <%= controller_class_name %>Controller do
8
22
 
9
- def <%= mock_file_name %>(stubs={})
10
- @<%= mock_file_name %> ||= mock_model(<%= class_name %>, stubs).as_null_object
23
+ # This should return the minimal set of attributes required to create a valid
24
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
25
+ # update the return value of this method accordingly.
26
+ def valid_attributes
27
+ {}
11
28
  end
12
29
 
13
30
  <% unless options[:singleton] -%>
14
31
  describe "GET index" do
15
32
  it "assigns all <%= table_name.pluralize %> as @<%= table_name.pluralize %>" do
16
- <%= stub orm_class.all(class_name) %> { [<%= mock_file_name %>] }
33
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
17
34
  get :index
18
- assigns(:<%= table_name %>).should eq([<%= mock_file_name %>])
35
+ assigns(:<%= table_name %>).should eq([<%= file_name %>])
19
36
  end
20
37
  end
21
38
 
22
39
  <% end -%>
23
40
  describe "GET show" do
24
- it "assigns the requested <%= file_name %> as @<%= file_name %>" do
25
- <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
26
- get :show, :id => "37"
27
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
41
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
42
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
43
+ get :show, :id => <%= file_name %>.id.to_s
44
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
28
45
  end
29
46
  end
30
47
 
31
48
  describe "GET new" do
32
- it "assigns a new <%= file_name %> as @<%= file_name %>" do
33
- <%= stub orm_class.build(class_name) %> { <%= mock_file_name %> }
49
+ it "assigns a new <%= ns_file_name %> as @<%= ns_file_name %>" do
34
50
  get :new
35
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
51
+ assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
36
52
  end
37
53
  end
38
54
 
39
55
  describe "GET edit" do
40
- it "assigns the requested <%= file_name %> as @<%= file_name %>" do
41
- <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
42
- get :edit, :id => "37"
43
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
56
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
57
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
58
+ get :edit, :id => <%= file_name %>.id.to_s
59
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
44
60
  end
45
61
  end
46
62
 
47
63
  describe "POST create" do
48
64
  describe "with valid params" do
49
- it "assigns a newly created <%= file_name %> as @<%= file_name %>" do
50
- <%= stub orm_class.build(class_name, params) %> { <%= mock_file_name(:save => true) %> }
51
- post :create, :<%= file_name %> => <%= params %>
52
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
65
+ it "creates a new <%= class_name %>" do
66
+ expect {
67
+ post :create, :<%= ns_file_name %> => valid_attributes
68
+ }.to change(<%= class_name %>, :count).by(1)
53
69
  end
54
70
 
55
- it "redirects to the created <%= file_name %>" do
56
- <%= stub orm_class.build(class_name) %> { <%= mock_file_name(:save => true) %> }
57
- post :create, :<%= file_name %> => {}
58
- response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
71
+ it "assigns a newly created <%= ns_file_name %> as @<%= ns_file_name %>" do
72
+ post :create, :<%= ns_file_name %> => valid_attributes
73
+ assigns(:<%= ns_file_name %>).should be_a(<%= class_name %>)
74
+ assigns(:<%= ns_file_name %>).should be_persisted
75
+ end
76
+
77
+ it "redirects to the created <%= ns_file_name %>" do
78
+ post :create, :<%= ns_file_name %> => valid_attributes
79
+ response.should redirect_to(<%= class_name %>.last)
59
80
  end
60
81
  end
61
82
 
62
83
  describe "with invalid params" do
63
- it "assigns a newly created but unsaved <%= file_name %> as @<%= file_name %>" do
64
- <%= stub orm_class.build(class_name, params) %> { <%= mock_file_name(:save => false) %> }
65
- post :create, :<%= file_name %> => <%= params %>
66
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
84
+ it "assigns a newly created but unsaved <%= ns_file_name %> as @<%= ns_file_name %>" do
85
+ # Trigger the behavior that occurs when invalid params are submitted
86
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
87
+ post :create, :<%= ns_file_name %> => {}
88
+ assigns(:<%= ns_file_name %>).should be_a_new(<%= class_name %>)
67
89
  end
68
90
 
69
91
  it "re-renders the 'new' template" do
70
- <%= stub orm_class.build(class_name) %> { <%= mock_file_name(:save => false) %> }
71
- post :create, :<%= file_name %> => {}
92
+ # Trigger the behavior that occurs when invalid params are submitted
93
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
94
+ post :create, :<%= ns_file_name %> => {}
72
95
  response.should render_template("new")
73
96
  end
74
97
  end
@@ -76,50 +99,59 @@ describe <%= controller_class_name %>Controller do
76
99
 
77
100
  describe "PUT update" do
78
101
  describe "with valid params" do
79
- it "updates the requested <%= file_name %>" do
80
- <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
81
- mock_<%= should_receive orm_instance.update_attributes(params) %>
82
- put :update, :id => "37", :<%= file_name %> => <%= params %>
102
+ it "updates the requested <%= ns_file_name %>" do
103
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
104
+ # Assuming there are no other <%= table_name %> in the database, this
105
+ # specifies that the <%= class_name %> created on the previous line
106
+ # receives the :update_attributes message with whatever params are
107
+ # submitted in the request.
108
+ <%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= params %>)
109
+ put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => <%= params %>
83
110
  end
84
111
 
85
- it "assigns the requested <%= file_name %> as @<%= file_name %>" do
86
- <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => true) %> }
87
- put :update, :id => "1"
88
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
112
+ it "assigns the requested <%= ns_file_name %> as @<%= ns_file_name %>" do
113
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
114
+ put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
115
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
89
116
  end
90
117
 
91
- it "redirects to the <%= file_name %>" do
92
- <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => true) %> }
93
- put :update, :id => "1"
94
- response.should redirect_to(<%= table_name.singularize %>_url(<%= mock_file_name %>))
118
+ it "redirects to the <%= ns_file_name %>" do
119
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
120
+ put :update, :id => <%= file_name %>.id, :<%= ns_file_name %> => valid_attributes
121
+ response.should redirect_to(<%= file_name %>)
95
122
  end
96
123
  end
97
124
 
98
125
  describe "with invalid params" do
99
- it "assigns the <%= file_name %> as @<%= file_name %>" do
100
- <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
101
- put :update, :id => "1"
102
- assigns(:<%= file_name %>).should be(<%= mock_file_name %>)
126
+ it "assigns the <%= ns_file_name %> as @<%= ns_file_name %>" do
127
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
128
+ # Trigger the behavior that occurs when invalid params are submitted
129
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
130
+ put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
131
+ assigns(:<%= ns_file_name %>).should eq(<%= file_name %>)
103
132
  end
104
133
 
105
134
  it "re-renders the 'edit' template" do
106
- <%= stub orm_class.find(class_name) %> { <%= mock_file_name(:update_attributes => false) %> }
107
- put :update, :id => "1"
135
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
136
+ # Trigger the behavior that occurs when invalid params are submitted
137
+ <%= class_name %>.any_instance.stub(:save).and_return(false)
138
+ put :update, :id => <%= file_name %>.id.to_s, :<%= ns_file_name %> => {}
108
139
  response.should render_template("edit")
109
140
  end
110
141
  end
111
142
  end
112
143
 
113
144
  describe "DELETE destroy" do
114
- it "destroys the requested <%= file_name %>" do
115
- <%= stub orm_class.find(class_name, "37".inspect) %> { <%= mock_file_name %> }
116
- mock_<%= should_receive orm_instance.destroy %>
117
- delete :destroy, :id => "37"
145
+ it "destroys the requested <%= ns_file_name %>" do
146
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
147
+ expect {
148
+ delete :destroy, :id => <%= file_name %>.id.to_s
149
+ }.to change(<%= class_name %>, :count).by(-1)
118
150
  end
119
151
 
120
152
  it "redirects to the <%= table_name %> list" do
121
- <%= stub orm_class.find(class_name) %> { <%= mock_file_name %> }
122
- delete :destroy, :id => "1"
153
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
154
+ delete :destroy, :id => <%= file_name %>.id.to_s
123
155
  response.should redirect_to(<%= index_helper %>_url)
124
156
  end
125
157
  end
@@ -1,29 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
- describe "<%= table_name %>/edit.html.<%= options[:template_engine] %>" do
4
+ describe "<%= ns_table_name %>/edit.html.<%= options[:template_engine] %>" do
5
5
  before(:each) do
6
- @<%= file_name %> = assign(:<%= file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
6
+ @<%= ns_file_name %> = assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? '))' : ',' %>
7
7
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
8
  :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
9
  <% end -%>
10
10
  <%= output_attributes.empty? ? "" : " ))\n" -%>
11
11
  end
12
12
 
13
- it "renders the edit <%= file_name %> form" do
13
+ it "renders the edit <%= ns_file_name %> form" do
14
14
  render
15
15
 
16
16
  <% if webrat? -%>
17
- rendered.should have_selector("form", :action => <%= file_name %>_path(@<%= file_name %>), :method => "post") do |form|
17
+ rendered.should have_selector("form", :action => <%= ns_file_name %>_path(@<%= ns_file_name %>), :method => "post") do |form|
18
18
  <% for attribute in output_attributes -%>
19
- form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
19
+ form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
20
20
  <% end -%>
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 => <%= index_helper %>_path(@<%= file_name %>), :method => "post" do
24
+ assert_select "form", :action => <%= index_helper %>_path(@<%= ns_file_name %>), :method => "post" do
25
25
  <% for attribute in output_attributes -%>
26
- assert_select "<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]"
26
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
27
27
  <% end -%>
28
28
  end
29
29
  <% end -%>
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
- describe "<%= table_name %>/index.html.<%= options[:template_engine] %>" do
4
+ describe "<%= ns_table_name %>/index.html.<%= options[:template_engine] %>" do
5
5
  before(:each) do
6
6
  assign(:<%= table_name %>, [
7
7
  <% [1,2].each_with_index do |id, model_index| -%>
@@ -16,7 +16,7 @@ describe "<%= table_name %>/index.html.<%= options[:template_engine] %>" do
16
16
  ])
17
17
  end
18
18
 
19
- it "renders a list of <%= table_name %>" do
19
+ it "renders a list of <%= ns_table_name %>" do
20
20
  render
21
21
  <% for attribute in output_attributes -%>
22
22
  <% if webrat? -%>
@@ -1,28 +1,28 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
- describe "<%= table_name %>/new.html.<%= options[:template_engine] %>" do
4
+ describe "<%= ns_table_name %>/new.html.<%= options[:template_engine] %>" do
5
5
  before(:each) do
6
- assign(:<%= file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
6
+ assign(:<%= ns_file_name %>, stub_model(<%= class_name %><%= output_attributes.empty? ? ').as_new_record)' : ',' %>
7
7
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
8
  :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
9
  <% end -%>
10
10
  <%= !output_attributes.empty? ? " ).as_new_record)\n end" : " end" %>
11
11
 
12
- it "renders new <%= file_name %> form" do
12
+ it "renders new <%= ns_file_name %> form" do
13
13
  render
14
14
 
15
15
  <% if webrat? -%>
16
16
  rendered.should have_selector("form", :action => <%= table_name %>_path, :method => "post") do |form|
17
17
  <% for attribute in output_attributes -%>
18
- form.should have_selector("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]")
18
+ form.should have_selector("<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]")
19
19
  <% end -%>
20
20
  end
21
21
  <% else -%>
22
22
  # Run the generator again with the --webrat flag if you want to use webrat matchers
23
23
  assert_select "form", :action => <%= index_helper %>_path, :method => "post" do
24
24
  <% for attribute in output_attributes -%>
25
- assert_select "<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>", :name => "<%= file_name %>[<%= attribute.name %>]"
25
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
26
26
  <% end -%>
27
27
  end
28
28
  <% end -%>