rspec-rails 2.0.0.beta.13 → 2.0.0.beta.14.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.markdown +75 -54
  2. data/Rakefile +5 -2
  3. data/Upgrade.markdown +13 -13
  4. data/VERSION +1 -1
  5. data/features/controller_specs/{do_not_render_views.feature → isolation_from_views.feature} +12 -11
  6. data/features/controller_specs/render_views.feature +8 -8
  7. data/features/{routing_specs → matchers}/be_routable_matcher.feature +18 -2
  8. data/lib/generators/rspec/install/templates/spec/spec_helper.rb +2 -2
  9. data/lib/generators/rspec/scaffold/scaffold_generator.rb +9 -0
  10. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +1 -1
  11. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  12. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  13. data/lib/rspec/rails.rb +3 -0
  14. data/lib/rspec/rails/example/controller_example_group.rb +5 -8
  15. data/lib/rspec/rails/example/helper_example_group.rb +3 -6
  16. data/lib/rspec/rails/example/mailer_example_group.rb +2 -7
  17. data/lib/rspec/rails/example/request_example_group.rb +2 -6
  18. data/lib/rspec/rails/example/routing_example_group.rb +3 -4
  19. data/lib/rspec/rails/example/view_example_group.rb +3 -6
  20. data/lib/rspec/rails/matchers.rb +1 -11
  21. data/lib/rspec/rails/matchers/{routing_spec_matchers.rb → routing_matchers.rb} +2 -2
  22. data/lib/rspec/rails/mocks.rb +11 -1
  23. data/lib/rspec/rails/module_inclusion.rb +11 -0
  24. data/lib/rspec/rails/monkey/action_mailer/test_case.rb +48 -48
  25. data/lib/rspec/rails/view_rendering.rb +30 -6
  26. data/rspec-rails.gemspec +16 -12
  27. data/spec/rspec/rails/example/controller_example_group_spec.rb +8 -6
  28. data/spec/rspec/rails/example/helper_example_group_spec.rb +3 -7
  29. data/spec/rspec/rails/example/mailer_example_group_spec.rb +2 -7
  30. data/spec/rspec/rails/example/request_example_group_spec.rb +2 -7
  31. data/spec/rspec/rails/example/routing_example_group_spec.rb +2 -7
  32. data/spec/rspec/rails/example/view_example_group_spec.rb +2 -7
  33. data/spec/rspec/rails/matchers/route_to_spec.rb +2 -2
  34. data/spec/rspec/rails/mocks/mock_model_spec.rb +31 -0
  35. data/spec/spec_helper.rb +18 -0
  36. data/templates/generate_stuff.rb +1 -1
  37. metadata +28 -14
@@ -1,3 +1,5 @@
1
+ require 'webrat'
2
+
1
3
  require 'rspec/core'
2
4
  require 'rspec/rails/monkey'
3
5
  require 'rspec/rails/extensions'
@@ -6,5 +8,6 @@ require 'rspec/rails/adapters'
6
8
  require 'rspec/rails/matchers'
7
9
  require 'rspec/rails/fixture_support'
8
10
  require 'rspec/rails/mocks'
11
+ require 'rspec/rails/module_inclusion'
9
12
  require 'rspec/rails/example'
10
13
 
@@ -1,6 +1,3 @@
1
- require 'action_controller'
2
- require 'webrat'
3
-
4
1
  module RSpec::Rails
5
2
  # Extends ActionController::TestCase::Behavior to work with RSpec.
6
3
  #
@@ -75,16 +72,18 @@ module RSpec::Rails
75
72
  #
76
73
  module ControllerExampleGroup
77
74
  extend ActiveSupport::Concern
75
+ extend RSpec::Rails::ModuleInclusion
78
76
 
79
77
  include RSpec::Rails::SetupAndTeardownAdapter
80
78
  include RSpec::Rails::TestUnitAssertionAdapter
81
79
  include ActionController::TestCase::Behavior
82
80
  include RSpec::Rails::ViewRendering
83
- include Webrat::Matchers
84
81
  include Webrat::Methods
82
+ include Webrat::Matchers
85
83
  include RSpec::Matchers
86
84
  include RSpec::Rails::Matchers::RedirectTo
87
85
  include RSpec::Rails::Matchers::RenderTemplate
86
+ include RSpec::Rails::Matchers::RoutingMatchers
88
87
 
89
88
  module ClassMethods
90
89
  def controller_class
@@ -93,7 +92,7 @@ module RSpec::Rails
93
92
  end
94
93
 
95
94
  module InstanceMethods
96
- attr_reader :controller
95
+ attr_reader :controller, :routes
97
96
  end
98
97
 
99
98
  included do
@@ -103,8 +102,6 @@ module RSpec::Rails
103
102
  end
104
103
  end
105
104
 
106
- RSpec.configure do |c|
107
- c.include self, :example_group => { :file_path => /\bspec\/controllers\// }
108
- end
105
+ RSpec.configure &include_self_when_dir_matches('spec','controllers')
109
106
  end
110
107
  end
@@ -1,6 +1,4 @@
1
- require 'action_view'
2
1
  require 'rspec/rails/view_assigns'
3
- require 'webrat'
4
2
 
5
3
  module RSpec::Rails
6
4
  # Extends ActionView::TestCase::Behavior
@@ -28,7 +26,8 @@ module RSpec::Rails
28
26
  # end
29
27
  #
30
28
  module HelperExampleGroup
31
- extend ActiveSupport::Concern
29
+ extend ActiveSupport::Concern
30
+ extend RSpec::Rails::ModuleInclusion
32
31
 
33
32
  include RSpec::Rails::SetupAndTeardownAdapter
34
33
  include RSpec::Rails::TestUnitAssertionAdapter
@@ -62,8 +61,6 @@ module RSpec::Rails
62
61
  end
63
62
  end
64
63
 
65
- RSpec.configure do |c|
66
- c.include self, :example_group => { :file_path => /\bspec\/helpers\// }
67
- end
64
+ RSpec.configure &include_self_when_dir_matches('spec','helpers')
68
65
  end
69
66
  end
@@ -1,12 +1,9 @@
1
- require 'action_mailer'
2
- require 'webrat'
3
-
4
1
  module RSpec::Rails
5
2
  module MailerExampleGroup
6
3
  extend ActiveSupport::Concern
4
+ extend RSpec::Rails::ModuleInclusion
7
5
 
8
6
  include ActionMailer::TestCase::Behavior
9
-
10
7
  include Webrat::Matchers
11
8
  include RSpec::Matchers
12
9
 
@@ -16,8 +13,6 @@ module RSpec::Rails
16
13
  end
17
14
  end
18
15
 
19
- RSpec.configure do |c|
20
- c.include self, :example_group => { :file_path => /\bspec\/mailers\// }
21
- end
16
+ RSpec.configure &include_self_when_dir_matches('spec','mailers')
22
17
  end
23
18
  end
@@ -1,6 +1,3 @@
1
- require 'action_dispatch'
2
- require 'webrat'
3
-
4
1
  module RSpec::Rails
5
2
  # Extends ActionDispatch::Integration::Runner to work with RSpec.
6
3
  #
@@ -16,6 +13,7 @@ module RSpec::Rails
16
13
  # => delegates to assert_redirected_to(destination)
17
14
  module RequestExampleGroup
18
15
  extend ActiveSupport::Concern
16
+ extend RSpec::Rails::ModuleInclusion
19
17
 
20
18
  include ActionDispatch::Integration::Runner
21
19
  include RSpec::Rails::TestUnitAssertionAdapter
@@ -47,8 +45,6 @@ module RSpec::Rails
47
45
  end
48
46
  end
49
47
 
50
- RSpec.configure do |c|
51
- c.include self, :example_group => { :file_path => /\bspec\/requests\// }
52
- end
48
+ RSpec.configure &include_self_when_dir_matches('spec','requests')
53
49
  end
54
50
  end
@@ -3,10 +3,11 @@ require "action_dispatch/testing/assertions/routing"
3
3
  module RSpec::Rails
4
4
  module RoutingExampleGroup
5
5
  extend ActiveSupport::Concern
6
+ extend RSpec::Rails::ModuleInclusion
6
7
 
7
8
  include RSpec::Rails::TestUnitAssertionAdapter
8
9
  include ActionDispatch::Assertions::RoutingAssertions
9
- include RSpec::Rails::RoutingSpecMatchers
10
+ include RSpec::Rails::Matchers::RoutingMatchers
10
11
 
11
12
  module InstanceMethods
12
13
  attr_reader :routes
@@ -18,8 +19,6 @@ module RSpec::Rails
18
19
  end
19
20
  end
20
21
 
21
- RSpec.configure do |c|
22
- c.include self, :example_group => { :file_path => /\bspec\/routing\// }
23
- end
22
+ RSpec.configure &include_self_when_dir_matches('spec','routing')
24
23
  end
25
24
  end
@@ -1,6 +1,4 @@
1
- require 'action_view'
2
1
  require 'rspec/rails/view_assigns'
3
- require 'webrat'
4
2
 
5
3
  module RSpec::Rails
6
4
  # Extends ActionView::TestCase::Behavior
@@ -20,7 +18,8 @@ module RSpec::Rails
20
18
  # end
21
19
  # end
22
20
  module ViewExampleGroup
23
- extend ActiveSupport::Concern
21
+ extend ActiveSupport::Concern
22
+ extend RSpec::Rails::ModuleInclusion
24
23
 
25
24
  include RSpec::Rails::SetupAndTeardownAdapter
26
25
  include RSpec::Rails::TestUnitAssertionAdapter
@@ -108,8 +107,6 @@ module RSpec::Rails
108
107
  end
109
108
  end
110
109
 
111
- RSpec.configure do |c|
112
- c.include self, :example_group => { :file_path => /\bspec\/views\// }
113
- end
110
+ RSpec.configure &include_self_when_dir_matches('spec','views')
114
111
  end
115
112
  end
@@ -7,16 +7,6 @@ module RSpec::Rails
7
7
  end
8
8
  end
9
9
 
10
- begin
11
- require "active_record"
12
- rescue LoadError
13
- end
14
-
15
- begin
16
- require "action_controller"
17
- rescue LoadError
18
- end
19
-
20
10
  begin
21
11
  require 'test/unit/assertionfailederror'
22
12
  rescue LoadError
@@ -30,6 +20,6 @@ end
30
20
 
31
21
  require 'rspec/rails/matchers/render_template'
32
22
  require 'rspec/rails/matchers/redirect_to'
33
- require 'rspec/rails/matchers/routing_spec_matchers'
23
+ require 'rspec/rails/matchers/routing_matchers'
34
24
  require 'rspec/rails/matchers/be_a_new'
35
25
  require 'rspec/rails/matchers/have_extension'
@@ -1,5 +1,5 @@
1
- module RSpec::Rails
2
- module RoutingSpecMatchers
1
+ module RSpec::Rails::Matchers
2
+ module RoutingMatchers
3
3
  extend RSpec::Matchers::DSL
4
4
 
5
5
  matcher :route_to do |route_options|
@@ -22,6 +22,10 @@ module RSpec
22
22
  def persisted?
23
23
  !!id
24
24
  end
25
+
26
+ def destroy
27
+ self.stub(:id) { nil }
28
+ end
25
29
  end
26
30
 
27
31
  # Creates a mock object instance for a +model_class+ with common
@@ -38,7 +42,13 @@ module RSpec
38
42
  m = mock(derived_name, options_and_stubs)
39
43
  m.extend InstanceMethods
40
44
  m.extend ActiveModel::Conversion
41
- m.stub(:errors) { ActiveModel::Errors.new(m) }
45
+ errors = ActiveModel::Errors.new(m)
46
+ [:save, :update_attributes].each do |key|
47
+ if options_and_stubs[key] == false
48
+ errors.stub(:empty?) { false }
49
+ end
50
+ end
51
+ m.stub(:errors) { errors }
42
52
  m.__send__(:__mock_proxy).instance_eval(<<-CODE, __FILE__, __LINE__)
43
53
  def @object.is_a?(other)
44
54
  #{model_class}.ancestors.include?(other)
@@ -0,0 +1,11 @@
1
+ module RSpec::Rails
2
+ module ModuleInclusion
3
+ def include_self_when_dir_matches(*path_parts)
4
+ lambda do |c|
5
+ c.include self, :example_group => {
6
+ :file_path => Regexp.compile(path_parts.join('[\\\/]'))
7
+ }
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,69 +1,69 @@
1
- require 'action_mailer'
1
+ if defined?(ActionMailer)
2
+ module ActionMailer
3
+ unless defined?(ActionMailer::TestCase::Behavior)
4
+ class TestCase < ActiveSupport::TestCase
5
+ module Behavior
6
+ extend ActiveSupport::Concern
2
7
 
3
- module ActionMailer
4
- unless defined?(ActionMailer::TestCase::Behavior)
5
- class TestCase < ActiveSupport::TestCase
6
- module Behavior
7
- extend ActiveSupport::Concern
8
+ include TestHelper
8
9
 
9
- include TestHelper
10
+ module ClassMethods
11
+ def tests(mailer)
12
+ write_inheritable_attribute(:mailer_class, mailer)
13
+ end
10
14
 
11
- module ClassMethods
12
- def tests(mailer)
13
- write_inheritable_attribute(:mailer_class, mailer)
14
- end
15
+ def mailer_class
16
+ if mailer = read_inheritable_attribute(:mailer_class)
17
+ mailer
18
+ else
19
+ tests determine_default_mailer(name)
20
+ end
21
+ end
15
22
 
16
- def mailer_class
17
- if mailer = read_inheritable_attribute(:mailer_class)
18
- mailer
19
- else
20
- tests determine_default_mailer(name)
23
+ def determine_default_mailer(name)
24
+ name.sub(/Test$/, '').constantize
25
+ rescue NameError => e
26
+ raise NonInferrableMailerError.new(name)
21
27
  end
22
28
  end
23
29
 
24
- def determine_default_mailer(name)
25
- name.sub(/Test$/, '').constantize
26
- rescue NameError => e
27
- raise NonInferrableMailerError.new(name)
28
- end
29
- end
30
+ module InstanceMethods
30
31
 
31
- module InstanceMethods
32
+ protected
32
33
 
33
- protected
34
+ def initialize_test_deliveries
35
+ ActionMailer::Base.delivery_method = :test
36
+ ActionMailer::Base.perform_deliveries = true
37
+ ActionMailer::Base.deliveries.clear
38
+ end
34
39
 
35
- def initialize_test_deliveries
36
- ActionMailer::Base.delivery_method = :test
37
- ActionMailer::Base.perform_deliveries = true
38
- ActionMailer::Base.deliveries.clear
39
- end
40
+ def set_expected_mail
41
+ @expected = Mail.new
42
+ @expected.content_type ["text", "plain", { "charset" => charset }]
43
+ @expected.mime_version = '1.0'
44
+ end
40
45
 
41
- def set_expected_mail
42
- @expected = Mail.new
43
- @expected.content_type ["text", "plain", { "charset" => charset }]
44
- @expected.mime_version = '1.0'
45
- end
46
+ private
46
47
 
47
- private
48
+ def charset
49
+ "UTF-8"
50
+ end
48
51
 
49
- def charset
50
- "UTF-8"
51
- end
52
+ def encode(subject)
53
+ Mail::Encodings.q_value_encode(subject, charset)
54
+ end
52
55
 
53
- def encode(subject)
54
- Mail::Encodings.q_value_encode(subject, charset)
56
+ def read_fixture(action)
57
+ IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
58
+ end
55
59
  end
56
60
 
57
- def read_fixture(action)
58
- IO.readlines(File.join(Rails.root, 'test', 'fixtures', self.class.mailer_class.name.underscore, action))
61
+ included do
62
+ setup :initialize_test_deliveries
63
+ setup :set_expected_mail
59
64
  end
60
65
  end
61
-
62
- included do
63
- setup :initialize_test_deliveries
64
- setup :set_expected_mail
65
- end
66
66
  end
67
67
  end
68
68
  end
69
- end
69
+ end
@@ -1,4 +1,3 @@
1
- require 'action_controller'
2
1
  require 'action_view/testing/resolvers'
3
2
 
4
3
  module RSpec
@@ -21,17 +20,42 @@ module RSpec
21
20
  end
22
21
  end
23
22
 
23
+ # Delegates find_all to the submitted controller's view_paths and then
24
+ # returns templates with modified source
25
+ class PathSetDelegatorResolver < ::ActionView::Resolver
26
+ attr_reader :path_set
27
+
28
+ def initialize(path_set)
29
+ @path_set = path_set
30
+ end
31
+
32
+ def find_all(*args)
33
+ templates = path_set.find_all(*args)
34
+ templates.each do |t|
35
+ t.singleton_class.class_eval do
36
+ def source
37
+ "Template source generated by RSpec."
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+
24
44
  included do
25
45
  before do
26
- @_view_paths = controller.class.view_paths
27
- controller.class.view_paths = [ActionView::NullResolver.new()] unless
28
- self.class.render_views?
46
+ unless self.class.render_views?
47
+ @_path_set_delegator_resolver = PathSetDelegatorResolver.new(@controller.class.view_paths)
48
+ @controller.class.view_paths = ::ActionView::PathSet.new.push(@_path_set_delegator_resolver)
49
+ end
29
50
  end
30
-
51
+
31
52
  after do
32
- controller.class.view_paths = @_view_paths
53
+ unless self.class.render_views?
54
+ @controller.class.view_paths = @_path_set_delegator_resolver.path_set
55
+ end
33
56
  end
34
57
  end
58
+
35
59
  end
36
60
  end
37
61
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rspec-rails}
8
- s.version = "2.0.0.beta.13"
8
+ s.version = "2.0.0.beta.14.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-06-23}
12
+ s.date = %q{2010-06-27}
13
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 = [
@@ -25,13 +25,13 @@ Gem::Specification.new do |s|
25
25
  "VERSION",
26
26
  "autotest/discover.rb",
27
27
  "cucumber.yml",
28
- "features/controller_specs/do_not_render_views.feature",
28
+ "features/controller_specs/isolation_from_views.feature",
29
29
  "features/controller_specs/readers.feature",
30
30
  "features/controller_specs/render_views.feature",
31
+ "features/matchers/be_routable_matcher.feature",
31
32
  "features/matchers/new_record_matcher.feature",
32
33
  "features/model_specs/errors_on.feature",
33
34
  "features/model_specs/transactional_examples.feature",
34
- "features/routing_specs/be_routable_matcher.feature",
35
35
  "features/step_definitions/model_steps.rb",
36
36
  "features/support/env.rb",
37
37
  "features/view_specs/view_spec.feature",
@@ -85,8 +85,9 @@ Gem::Specification.new do |s|
85
85
  "lib/rspec/rails/matchers/have_extension.rb",
86
86
  "lib/rspec/rails/matchers/redirect_to.rb",
87
87
  "lib/rspec/rails/matchers/render_template.rb",
88
- "lib/rspec/rails/matchers/routing_spec_matchers.rb",
88
+ "lib/rspec/rails/matchers/routing_matchers.rb",
89
89
  "lib/rspec/rails/mocks.rb",
90
+ "lib/rspec/rails/module_inclusion.rb",
90
91
  "lib/rspec/rails/monkey.rb",
91
92
  "lib/rspec/rails/monkey/action_mailer/test_case.rb",
92
93
  "lib/rspec/rails/version.rb",
@@ -118,7 +119,7 @@ Gem::Specification.new do |s|
118
119
  s.homepage = %q{http://github.com/rspec/rspec-rails}
119
120
  s.post_install_message = %q{**************************************************
120
121
 
121
- Thank you for installing rspec-rails-2.0.0.beta.13!
122
+ Thank you for installing rspec-rails-2.0.0.beta.14.1!
122
123
 
123
124
  This version of rspec-rails only works with
124
125
  versions of rails >= 3.0.0.pre.
@@ -128,13 +129,16 @@ Gem::Specification.new do |s|
128
129
 
129
130
  script/rails generate rspec:install
130
131
 
132
+ Also, be sure to look at Upgrade.markdown to see
133
+ what might have changed since the last release.
134
+
131
135
  **************************************************
132
136
  }
133
137
  s.rdoc_options = ["--charset=UTF-8"]
134
138
  s.require_paths = ["lib"]
135
139
  s.rubyforge_project = %q{rspec}
136
- s.rubygems_version = %q{1.3.6}
137
- s.summary = %q{rspec-rails-2.0.0.beta.13}
140
+ s.rubygems_version = %q{1.3.7}
141
+ s.summary = %q{rspec-rails-2.0.0.beta.14.1}
138
142
  s.test_files = [
139
143
  "spec/rspec/rails/example/controller_example_group_spec.rb",
140
144
  "spec/rspec/rails/example/helper_example_group_spec.rb",
@@ -159,15 +163,15 @@ Gem::Specification.new do |s|
159
163
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
160
164
  s.specification_version = 3
161
165
 
162
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
163
- s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.13"])
166
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
167
+ s.add_runtime_dependency(%q<rspec>, [">= 2.0.0.beta.14"])
164
168
  s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
165
169
  else
166
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.13"])
170
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.14"])
167
171
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
168
172
  end
169
173
  else
170
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.13"])
174
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.14"])
171
175
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
172
176
  end
173
177
  end