rspec-rails 2.0.0.beta.8 → 2.0.0.beta.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/README.markdown +82 -27
  2. data/Rakefile +7 -7
  3. data/Upgrade.markdown +12 -0
  4. data/VERSION +1 -1
  5. data/autotest/discover.rb +1 -0
  6. data/cucumber.yml +3 -0
  7. data/example_app_template.rb +2 -2
  8. data/features/controller_specs/do_not_render_views.feature +61 -0
  9. data/features/controller_specs/readers.feature +18 -0
  10. data/features/controller_specs/render_views.feature +53 -0
  11. data/features/model_specs/errors_on.feature +32 -0
  12. data/features/model_specs/transactional_examples.feature +2 -2
  13. data/features/view_specs/view_spec.feature +102 -1
  14. data/lib/autotest/rails_rspec2.rb +1 -1
  15. data/lib/generators/rspec/helper/helper_generator.rb +1 -0
  16. data/lib/generators/rspec/helper/templates/helper_spec.rb +3 -3
  17. data/lib/generators/rspec/install/install_generator.rb +7 -7
  18. data/lib/generators/rspec/scaffold/scaffold_generator.rb +10 -1
  19. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  20. data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
  21. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
  22. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  23. data/lib/rspec-rails.rb +12 -0
  24. data/lib/rspec/rails.rb +8 -0
  25. data/lib/rspec/rails/adapters.rb +12 -8
  26. data/lib/rspec/rails/example.rb +1 -0
  27. data/lib/rspec/rails/example/controller_example_group.rb +13 -12
  28. data/lib/rspec/rails/example/helper_example_group.rb +43 -0
  29. data/lib/rspec/rails/example/mailer_example_group.rb +10 -5
  30. data/lib/rspec/rails/example/request_example_group.rb +7 -7
  31. data/lib/rspec/rails/example/view_example_group.rb +44 -62
  32. data/lib/rspec/rails/extensions.rb +1 -0
  33. data/lib/rspec/rails/extensions/active_record/base.rb +46 -0
  34. data/lib/rspec/rails/matchers.rb +28 -3
  35. data/lib/rspec/rails/mocks.rb +3 -3
  36. data/lib/rspec/rails/monkey.rb +1 -0
  37. data/lib/rspec/rails/monkey/action_controller/test_case.rb +153 -145
  38. data/lib/rspec/rails/monkey/action_view/test_case.rb +201 -0
  39. data/lib/rspec/rails/null_resolver.rb +10 -0
  40. data/lib/{generators/rspec/install/templates/lib → rspec/rails}/tasks/rspec.rake +4 -5
  41. data/lib/rspec/rails/transactional_database_support.rb +4 -6
  42. data/lib/rspec/rails/version.rb +1 -1
  43. data/lib/rspec/rails/view_assigns.rb +28 -0
  44. data/lib/rspec/rails/view_rendering.rb +33 -0
  45. data/rspec-rails.gemspec +41 -11
  46. data/spec/rspec/rails/example/controller_example_group_spec.rb +11 -0
  47. data/spec/rspec/rails/example/helper_example_group_spec.rb +20 -0
  48. data/spec/rspec/rails/example/mailer_example_group_spec.rb +11 -0
  49. data/spec/rspec/rails/example/request_example_group_spec.rb +11 -0
  50. data/spec/rspec/rails/example/view_example_group_spec.rb +75 -0
  51. data/spec/rspec/rails/example/view_rendering_spec.rb +68 -0
  52. data/spec/rspec/rails/matchers/errors_on_spec.rb +38 -0
  53. data/spec/rspec/rails/mocks/ar_classes.rb +1 -1
  54. data/spec/rspec/rails/mocks/mock_model_spec.rb +88 -65
  55. data/spec/rspec/rails/mocks/stub_model_spec.rb +1 -1
  56. data/spec/rspec/rails/transactional_database_support_spec.rb +2 -2
  57. data/spec/spec_helper.rb +18 -2
  58. data/spec/support/helpers.rb +20 -0
  59. data/specs.watchr +10 -10
  60. data/templates/generate_stuff.rb +3 -1
  61. metadata +40 -9
@@ -0,0 +1,201 @@
1
+ require 'active_support/core_ext/object/blank'
2
+ require 'action_controller'
3
+ require 'action_controller/test_case'
4
+ require 'action_view'
5
+
6
+ unless defined?(ActionView::TestCase::Behavior)
7
+
8
+
9
+ # This has been merged to rails HEAD after the 3.0.0.beta.3 release (see
10
+ # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4678).
11
+ # Once 3.0.0.rc.1 comes out, we can remove it.
12
+ module ActionView
13
+
14
+ # This line is NOT part of the code merged into Rails, but ensures that
15
+ # we're using the correct code for rails-3.0.0.beta.3
16
+ remove_const :TestCase
17
+
18
+ class TestCase < ActiveSupport::TestCase
19
+ class TestController < ActionController::Base
20
+ include ActionDispatch::TestProcess
21
+
22
+ attr_accessor :request, :response, :params
23
+
24
+ class << self
25
+ attr_writer :controller_path
26
+ end
27
+
28
+ def controller_path=(path)
29
+ self.class.controller_path=(path)
30
+ end
31
+
32
+ def initialize
33
+ self.class.controller_path = ""
34
+ @request = ActionController::TestRequest.new
35
+ @response = ActionController::TestResponse.new
36
+
37
+ @request.env.delete('PATH_INFO')
38
+
39
+ @params = {}
40
+ end
41
+ end
42
+
43
+ module Behavior
44
+ extend ActiveSupport::Concern
45
+
46
+ include ActionDispatch::Assertions, ActionDispatch::TestProcess
47
+ include ActionController::TemplateAssertions
48
+ include ActionView::Context
49
+
50
+ include ActionController::PolymorphicRoutes
51
+ include ActionController::RecordIdentifier
52
+
53
+ include AbstractController::Helpers
54
+ include ActionView::Helpers
55
+
56
+ attr_accessor :controller, :output_buffer, :rendered
57
+
58
+ module ClassMethods
59
+ def tests(helper_class)
60
+ self.helper_class = helper_class
61
+ end
62
+
63
+ def determine_default_helper_class(name)
64
+ mod = name.sub(/Test$/, '').constantize
65
+ mod.is_a?(Class) ? nil : mod
66
+ rescue NameError
67
+ nil
68
+ end
69
+
70
+ def helper_method(*methods)
71
+ # Almost a duplicate from ActionController::Helpers
72
+ methods.flatten.each do |method|
73
+ _helpers.module_eval <<-end_eval
74
+ def #{method}(*args, &block) # def current_user(*args, &block)
75
+ _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block)
76
+ end # end
77
+ end_eval
78
+ end
79
+ end
80
+
81
+ attr_writer :helper_class
82
+
83
+ def helper_class
84
+ @helper_class ||= determine_default_helper_class(name)
85
+ end
86
+
87
+ private
88
+
89
+ def include_helper_modules!
90
+ helper(helper_class) if helper_class
91
+ include _helpers
92
+ end
93
+
94
+ end
95
+
96
+ def setup_with_controller
97
+ @controller = ActionView::TestCase::TestController.new
98
+ @output_buffer = ActiveSupport::SafeBuffer.new
99
+ @rendered = ''
100
+
101
+ self.class.send(:include_helper_modules!)
102
+ make_test_case_available_to_view!
103
+ say_no_to_protect_against_forgery!
104
+ end
105
+
106
+ def config
107
+ @controller.config if @controller.respond_to?(:config)
108
+ end
109
+
110
+ def render(options = {}, local_assigns = {}, &block)
111
+ @rendered << output = _view.render(options, local_assigns, &block)
112
+ output
113
+ end
114
+
115
+ included do
116
+ setup :setup_with_controller
117
+ end
118
+
119
+ private
120
+
121
+ # Support the selector assertions
122
+ #
123
+ # Need to experiment if this priority is the best one: rendered => output_buffer
124
+ def response_from_page_or_rjs
125
+ HTML::Document.new(@rendered.blank? ? @output_buffer : @rendered).root
126
+ end
127
+
128
+ def say_no_to_protect_against_forgery!
129
+ _helpers.module_eval do
130
+ def protect_against_forgery?
131
+ false
132
+ end
133
+ end
134
+ end
135
+
136
+ def make_test_case_available_to_view!
137
+ test_case_instance = self
138
+ _helpers.module_eval do
139
+ define_method(:_test_case) { test_case_instance }
140
+ private :_test_case
141
+ end
142
+ end
143
+
144
+ def _view
145
+ view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
146
+ view.singleton_class.send :include, _helpers
147
+ view.singleton_class.send :include, @controller._router.url_helpers
148
+ view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash"
149
+ view.output_buffer = self.output_buffer
150
+ view
151
+ end
152
+
153
+ EXCLUDE_IVARS = %w{
154
+ @_result
155
+ @output_buffer
156
+ @rendered
157
+ @templates
158
+ @view_context_class
159
+ @layouts
160
+ @partials
161
+ @controller
162
+
163
+ @method_name
164
+ @fixture_cache
165
+ @loaded_fixtures
166
+ @test_passed
167
+ }
168
+
169
+ def _instance_variables
170
+ instance_variables - EXCLUDE_IVARS
171
+ instance_variables
172
+ end
173
+
174
+ def _assigns
175
+ _instance_variables.inject({}) do |hash, var|
176
+ name = var[1..-1].to_sym
177
+ hash[name] = instance_variable_get(var)
178
+ hash
179
+ end
180
+ end
181
+
182
+ def _router
183
+ @controller._router if @controller.respond_to?(:_router)
184
+ end
185
+
186
+ def method_missing(selector, *args)
187
+ if @controller.respond_to?(:_router) &&
188
+ @controller._router.named_routes.helpers.include?(selector)
189
+ @controller.__send__(selector, *args)
190
+ else
191
+ super
192
+ end
193
+ end
194
+
195
+ end
196
+
197
+ include Behavior
198
+
199
+ end
200
+ end
201
+ end
@@ -0,0 +1,10 @@
1
+ module RSpec
2
+ module Rails
3
+ class NullResolver < ActionView::PathResolver
4
+ def query(path, exts, formats)
5
+ handler, format = extract_handler_and_format(path, formats)
6
+ [ActionView::Template.new("RSpec-generated template", path, handler, :virtual_path => path, :format => format)]
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,8 +1,8 @@
1
1
  begin
2
2
  require 'rspec/core'
3
3
  require 'rspec/core/rake_task'
4
- rescue MissingSourceFile
5
- module Rspec
4
+ rescue MissingSourceFile
5
+ module RSpec
6
6
  module Core
7
7
  class RakeTask
8
8
  def initialize(name)
@@ -36,12 +36,12 @@ task :default => :spec
36
36
  task :stats => "spec:statsetup"
37
37
 
38
38
  desc "Run all specs in spec directory (excluding plugin specs)"
39
- Rspec::Core::RakeTask.new(:spec => spec_prereq)
39
+ RSpec::Core::RakeTask.new(:spec => spec_prereq)
40
40
 
41
41
  namespace :spec do
42
42
  [:requests, :models, :controllers, :views, :helpers, :mailers, :lib].each do |sub|
43
43
  desc "Run the code examples in spec/#{sub}"
44
- Rspec::Core::RakeTask.new(sub => spec_prereq) do |t|
44
+ RSpec::Core::RakeTask.new(sub => spec_prereq) do |t|
45
45
  t.pattern = "./spec/#{sub}/**/*_spec.rb"
46
46
  end
47
47
  end
@@ -66,4 +66,3 @@ namespace :spec do
66
66
  ::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
67
67
  end
68
68
  end
69
-
@@ -1,6 +1,4 @@
1
- require 'rspec/core'
2
-
3
- module Rspec
1
+ module RSpec
4
2
  module Rails
5
3
  module TransactionalDatabaseSupport
6
4
 
@@ -9,7 +7,7 @@ module Rspec
9
7
  end
10
8
 
11
9
  def use_transactional_examples?
12
- active_record_configured? && Rspec.configuration.use_transactional_examples?
10
+ active_record_configured? && RSpec.configuration.use_transactional_examples?
13
11
  end
14
12
 
15
13
  def setup_transactional_examples
@@ -34,8 +32,8 @@ module Rspec
34
32
  end
35
33
  end
36
34
 
37
- Rspec.configure do |c|
38
- c.include Rspec::Rails::TransactionalDatabaseSupport
35
+ RSpec.configure do |c|
36
+ c.include RSpec::Rails::TransactionalDatabaseSupport
39
37
  c.before { setup_transactional_examples }
40
38
  c.after { teardown_transactional_examples }
41
39
  end
@@ -1,4 +1,4 @@
1
- module Rspec # :nodoc:
1
+ module RSpec # :nodoc:
2
2
  module Rails # :nodoc:
3
3
  module Version # :nodoc:
4
4
  STRING = File.readlines(File.expand_path('../../../../VERSION', __FILE__)).first
@@ -0,0 +1,28 @@
1
+ module RSpec
2
+ module Rails
3
+ module ViewAssigns
4
+ extend ActiveSupport::Concern
5
+
6
+ module InstanceMethods
7
+ # :callseq:
8
+ # assign(:widget, stub_model(Widget))
9
+ #
10
+ # Assigns a value to an instance variable in the scope of the
11
+ # view being rendered.
12
+ def assign(key, value)
13
+ _encapsulated_assigns[key] = value
14
+ end
15
+
16
+ private
17
+
18
+ def _encapsulated_assigns
19
+ @_encapsulated_assigns ||= {}
20
+ end
21
+
22
+ def _assigns
23
+ super.merge(_encapsulated_assigns)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module RSpec
2
+ module Rails
3
+ module ViewRendering
4
+ extend ActiveSupport::Concern
5
+
6
+ module ClassMethods
7
+ def metadata_for_rspec_rails
8
+ metadata[:rspec_rails] ||= {}
9
+ end
10
+
11
+ def render_views
12
+ metadata_for_rspec_rails[:render_views] = true
13
+ end
14
+
15
+ def render_views?
16
+ metadata_for_rspec_rails[:render_views]
17
+ end
18
+ end
19
+
20
+ included do
21
+ before do
22
+ @_view_paths = controller.class.view_paths
23
+ controller.class.view_paths = [RSpec::Rails::NullResolver.new()] unless
24
+ self.class.render_views?
25
+ end
26
+
27
+ after do
28
+ controller.class.view_paths = @_view_paths
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-rails}
8
- s.version = "2.0.0.beta.8"
8
+ s.version = "2.0.0.beta.9.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["David Chelimsky", "Chad Humphries"]
12
- s.date = %q{2010-04-27}
13
- s.description = %q{Rspec-2 for Rails-3}
12
+ s.date = %q{2010-05-27}
13
+ s.description = %q{RSpec-2 for Rails-3}
14
14
  s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README.markdown"
@@ -20,9 +20,16 @@ Gem::Specification.new do |s|
20
20
  "Gemfile",
21
21
  "README.markdown",
22
22
  "Rakefile",
23
+ "Upgrade.markdown",
23
24
  "VERSION",
25
+ "autotest/discover.rb",
26
+ "cucumber.yml",
24
27
  "example_app_template.rb",
28
+ "features/controller_specs/do_not_render_views.feature",
29
+ "features/controller_specs/readers.feature",
30
+ "features/controller_specs/render_views.feature",
25
31
  "features/matchers/new_record_matcher.feature",
32
+ "features/model_specs/errors_on.feature",
26
33
  "features/model_specs/transactional_examples.feature",
27
34
  "features/step_definitions/model_steps.rb",
28
35
  "features/support/env.rb",
@@ -37,7 +44,6 @@ Gem::Specification.new do |s|
37
44
  "lib/generators/rspec/install/install_generator.rb",
38
45
  "lib/generators/rspec/install/templates/autotest/discover.rb",
39
46
  "lib/generators/rspec/install/templates/config/initializers/rspec_generator.rb.tt",
40
- "lib/generators/rspec/install/templates/lib/tasks/rspec.rake",
41
47
  "lib/generators/rspec/install/templates/spec/spec_helper.rb",
42
48
  "lib/generators/rspec/integration/integration_generator.rb",
43
49
  "lib/generators/rspec/integration/templates/request_spec.rb",
@@ -63,18 +69,33 @@ Gem::Specification.new do |s|
63
69
  "lib/rspec/rails/adapters.rb",
64
70
  "lib/rspec/rails/example.rb",
65
71
  "lib/rspec/rails/example/controller_example_group.rb",
72
+ "lib/rspec/rails/example/helper_example_group.rb",
66
73
  "lib/rspec/rails/example/mailer_example_group.rb",
67
74
  "lib/rspec/rails/example/request_example_group.rb",
68
75
  "lib/rspec/rails/example/view_example_group.rb",
76
+ "lib/rspec/rails/extensions.rb",
77
+ "lib/rspec/rails/extensions/active_record/base.rb",
69
78
  "lib/rspec/rails/matchers.rb",
70
79
  "lib/rspec/rails/mocks.rb",
71
80
  "lib/rspec/rails/monkey.rb",
72
81
  "lib/rspec/rails/monkey/action_controller/test_case.rb",
82
+ "lib/rspec/rails/monkey/action_view/test_case.rb",
73
83
  "lib/rspec/rails/monkey/active_support/notifications/fanout.rb",
84
+ "lib/rspec/rails/null_resolver.rb",
85
+ "lib/rspec/rails/tasks/rspec.rake",
74
86
  "lib/rspec/rails/transactional_database_support.rb",
75
87
  "lib/rspec/rails/version.rb",
88
+ "lib/rspec/rails/view_assigns.rb",
89
+ "lib/rspec/rails/view_rendering.rb",
76
90
  "rspec-rails.gemspec",
91
+ "spec/rspec/rails/example/controller_example_group_spec.rb",
92
+ "spec/rspec/rails/example/helper_example_group_spec.rb",
93
+ "spec/rspec/rails/example/mailer_example_group_spec.rb",
94
+ "spec/rspec/rails/example/request_example_group_spec.rb",
95
+ "spec/rspec/rails/example/view_example_group_spec.rb",
96
+ "spec/rspec/rails/example/view_rendering_spec.rb",
77
97
  "spec/rspec/rails/matchers/be_a_new_spec.rb",
98
+ "spec/rspec/rails/matchers/errors_on_spec.rb",
78
99
  "spec/rspec/rails/matchers/redirect_to_spec.rb",
79
100
  "spec/rspec/rails/matchers/render_template_spec.rb",
80
101
  "spec/rspec/rails/mocks/ar_classes.rb",
@@ -82,6 +103,7 @@ Gem::Specification.new do |s|
82
103
  "spec/rspec/rails/mocks/stub_model_spec.rb",
83
104
  "spec/rspec/rails/transactional_database_support_spec.rb",
84
105
  "spec/spec_helper.rb",
106
+ "spec/support/helpers.rb",
85
107
  "specs.watchr",
86
108
  "templates/generate_stuff.rb",
87
109
  "templates/run_specs.rb"
@@ -89,7 +111,7 @@ Gem::Specification.new do |s|
89
111
  s.homepage = %q{http://github.com/rspec/rspec-rails}
90
112
  s.post_install_message = %q{**************************************************
91
113
 
92
- Thank you for installing rspec-rails-2.0.0.beta.8!
114
+ Thank you for installing rspec-rails-2.0.0.beta.9.1!
93
115
 
94
116
  This version of rspec-rails only works with
95
117
  versions of rails >= 3.0.0.pre.
@@ -104,16 +126,24 @@ Gem::Specification.new do |s|
104
126
  s.require_paths = ["lib"]
105
127
  s.rubyforge_project = %q{rspec}
106
128
  s.rubygems_version = %q{1.3.6}
107
- s.summary = %q{rspec-rails-2.0.0.beta.8}
129
+ s.summary = %q{rspec-rails-2.0.0.beta.9.1}
108
130
  s.test_files = [
109
- "spec/rspec/rails/matchers/be_a_new_spec.rb",
131
+ "spec/rspec/rails/example/controller_example_group_spec.rb",
132
+ "spec/rspec/rails/example/helper_example_group_spec.rb",
133
+ "spec/rspec/rails/example/mailer_example_group_spec.rb",
134
+ "spec/rspec/rails/example/request_example_group_spec.rb",
135
+ "spec/rspec/rails/example/view_example_group_spec.rb",
136
+ "spec/rspec/rails/example/view_rendering_spec.rb",
137
+ "spec/rspec/rails/matchers/be_a_new_spec.rb",
138
+ "spec/rspec/rails/matchers/errors_on_spec.rb",
110
139
  "spec/rspec/rails/matchers/redirect_to_spec.rb",
111
140
  "spec/rspec/rails/matchers/render_template_spec.rb",
112
141
  "spec/rspec/rails/mocks/ar_classes.rb",
113
142
  "spec/rspec/rails/mocks/mock_model_spec.rb",
114
143
  "spec/rspec/rails/mocks/stub_model_spec.rb",
115
144
  "spec/rspec/rails/transactional_database_support_spec.rb",
116
- "spec/spec_helper.rb"
145
+ "spec/spec_helper.rb",
146
+ "spec/support/helpers.rb"
117
147
  ]
118
148
 
119
149
  if s.respond_to? :specification_version then
@@ -121,14 +151,14 @@ Gem::Specification.new do |s|
121
151
  s.specification_version = 3
122
152
 
123
153
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
124
- s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.8"])
154
+ s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.9"])
125
155
  s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
126
156
  else
127
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.8"])
157
+ s.add_dependency(%q<rspec>, ["= 2.0.0.beta.9"])
128
158
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
129
159
  end
130
160
  else
131
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.8"])
161
+ s.add_dependency(%q<rspec>, ["= 2.0.0.beta.9"])
132
162
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
133
163
  end
134
164
  end