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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/Gemfile +8 -2
  2. data/README.markdown +39 -0
  3. data/Rakefile +16 -32
  4. data/VERSION +1 -1
  5. data/features/routing_specs/be_routable_matcher.feature +64 -0
  6. data/features/support/env.rb +19 -2
  7. data/lib/autotest/rails_rspec2.rb +4 -1
  8. data/lib/generators/rspec/install/templates/lib/tasks/rspec.rake +1 -1
  9. data/lib/generators/rspec/scaffold/scaffold_generator.rb +1 -1
  10. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  11. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
  12. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  13. data/lib/rspec/rails.rb +0 -1
  14. data/lib/rspec/rails/adapters.rb +2 -2
  15. data/lib/rspec/rails/example.rb +1 -0
  16. data/lib/rspec/rails/example/controller_example_group.rb +3 -1
  17. data/lib/rspec/rails/example/helper_example_group.rb +3 -2
  18. data/lib/rspec/rails/example/mailer_example_group.rb +1 -0
  19. data/lib/rspec/rails/example/request_example_group.rb +15 -0
  20. data/lib/rspec/rails/example/routing_example_group.rb +25 -0
  21. data/lib/rspec/rails/example/view_example_group.rb +21 -7
  22. data/lib/rspec/rails/matchers.rb +16 -58
  23. data/lib/rspec/rails/matchers/be_a_new.rb +5 -0
  24. data/lib/rspec/rails/matchers/have_extension.rb +23 -0
  25. data/lib/rspec/rails/matchers/redirect_to.rb +15 -0
  26. data/lib/rspec/rails/matchers/render_template.rb +16 -0
  27. data/lib/rspec/rails/matchers/routing_spec_matchers.rb +28 -0
  28. data/lib/rspec/rails/monkey.rb +0 -3
  29. data/lib/rspec/rails/view_rendering.rb +4 -1
  30. data/rspec-rails.gemspec +18 -11
  31. data/spec/rspec/rails/example/helper_example_group_spec.rb +1 -1
  32. data/spec/rspec/rails/example/routing_example_group_spec.rb +13 -0
  33. data/spec/rspec/rails/example/view_example_group_spec.rb +3 -0
  34. data/spec/rspec/rails/matchers/redirect_to_spec.rb +1 -1
  35. data/spec/rspec/rails/matchers/render_template_spec.rb +1 -1
  36. data/spec/rspec/rails/matchers/route_to_spec.rb +53 -0
  37. data/templates/Gemfile +7 -26
  38. data/templates/run_specs.rb +1 -1
  39. metadata +26 -19
  40. data/lib/rspec/rails/monkey/action_controller/test_case.rb +0 -207
  41. data/lib/rspec/rails/monkey/action_view/test_case.rb +0 -203
  42. data/lib/rspec/rails/monkey/active_support/notifications/fanout.rb +0 -20
  43. data/lib/rspec/rails/null_resolver.rb +0 -10
@@ -2,14 +2,8 @@ require 'rspec/core/deprecation'
2
2
  require 'rspec/core/backward_compatibility'
3
3
  require 'rspec/matchers'
4
4
 
5
- begin
6
- require 'test/unit/assertionfailederror'
7
- rescue LoadError
8
- module Test
9
- module Unit
10
- class AssertionFailedError < StandardError
11
- end
12
- end
5
+ module RSpec::Rails
6
+ module Matchers
13
7
  end
14
8
  end
15
9
 
@@ -18,60 +12,24 @@ begin
18
12
  rescue LoadError
19
13
  end
20
14
 
21
- module RSpec::Rails
22
- module ControllerSpecMatchers
23
- extend RSpec::Matchers::DSL
24
-
25
- matcher :redirect_to do |destination|
26
- match_unless_raises Test::Unit::AssertionFailedError do |_|
27
- assert_redirected_to destination
28
- end
29
-
30
- failure_message_for_should do
31
- rescued_exception.message
32
- end
33
- end
34
-
35
- matcher :render_template do |options, message|
36
- match_unless_raises Test::Unit::AssertionFailedError do |_|
37
- options = options.to_s if Symbol === options
38
- assert_template options, message
39
- end
40
-
41
- failure_message_for_should do
42
- rescued_exception.message
43
- end
44
- end
45
- end
46
- end
47
-
48
- RSpec::Matchers.define :be_a_new do |model_klass|
49
- match do |actual|
50
- model_klass === actual && actual.new_record?
51
- end
15
+ begin
16
+ require "action_controller"
17
+ rescue LoadError
52
18
  end
53
19
 
54
- require 'rspec/matchers/have'
55
-
56
- module RSpec #:nodoc:
57
- module Matchers #:nodoc:
58
- class Have #:nodoc:
59
-
60
- def failure_message_for_should_with_errors_on_extensions
61
- return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
62
- return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
63
- return failure_message_for_should_without_errors_on_extensions
64
- end
65
- alias_method_chain :failure_message_for_should, :errors_on_extensions
66
-
67
- def description_with_errors_on_extensions
68
- return "have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
69
- return "have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
70
- return description_without_errors_on_extensions
20
+ begin
21
+ require 'test/unit/assertionfailederror'
22
+ rescue LoadError
23
+ module Test
24
+ module Unit
25
+ class AssertionFailedError < StandardError
71
26
  end
72
- alias_method_chain :description, :errors_on_extensions
73
-
74
27
  end
75
28
  end
76
29
  end
77
30
 
31
+ require 'rspec/rails/matchers/render_template'
32
+ require 'rspec/rails/matchers/redirect_to'
33
+ require 'rspec/rails/matchers/routing_spec_matchers'
34
+ require 'rspec/rails/matchers/be_a_new'
35
+ require 'rspec/rails/matchers/have_extension'
@@ -0,0 +1,5 @@
1
+ RSpec::Matchers.define :be_a_new do |model_klass|
2
+ match do |actual|
3
+ model_klass === actual && actual.new_record?
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ require 'active_support/core_ext/module/aliasing'
2
+ require 'rspec/matchers/have'
3
+
4
+ module RSpec #:nodoc:
5
+ module Matchers #:nodoc:
6
+ class Have #:nodoc:
7
+ def failure_message_for_should_with_errors_on_extensions
8
+ return "expected #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}, got #{@actual}" if @collection_name == :errors_on
9
+ return "expected #{relativities[@relativity]}#{@expected} error on :#{@args[0]}, got #{@actual}" if @collection_name == :error_on
10
+ return failure_message_for_should_without_errors_on_extensions
11
+ end
12
+ alias_method_chain :failure_message_for_should, :errors_on_extensions
13
+
14
+ def description_with_errors_on_extensions
15
+ return "have #{relativities[@relativity]}#{@expected} errors on :#{@args[0]}" if @collection_name == :errors_on
16
+ return "have #{relativities[@relativity]}#{@expected} error on :#{@args[0]}" if @collection_name == :error_on
17
+ return description_without_errors_on_extensions
18
+ end
19
+ alias_method_chain :description, :errors_on_extensions
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,15 @@
1
+ module RSpec::Rails::Matchers
2
+ module RedirectTo
3
+ extend RSpec::Matchers::DSL
4
+
5
+ matcher :redirect_to do |destination|
6
+ match_unless_raises Test::Unit::AssertionFailedError do |_|
7
+ assert_redirected_to destination
8
+ end
9
+
10
+ failure_message_for_should do
11
+ rescued_exception.message
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module RSpec::Rails::Matchers
2
+ module RenderTemplate
3
+ extend RSpec::Matchers::DSL
4
+
5
+ matcher :render_template do |options, message|
6
+ match_unless_raises Test::Unit::AssertionFailedError do |_|
7
+ options = options.to_s if Symbol === options
8
+ assert_template options, message
9
+ end
10
+
11
+ failure_message_for_should do
12
+ rescued_exception.message
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,28 @@
1
+ module RSpec::Rails
2
+ module RoutingSpecMatchers
3
+ extend RSpec::Matchers::DSL
4
+
5
+ matcher :route_to do |route_options|
6
+ match_unless_raises Test::Unit::AssertionFailedError do |path|
7
+ assertion_path = { :method => path.keys.first, :path => path.values.first }
8
+ assert_routing(assertion_path, route_options)
9
+ end
10
+
11
+ failure_message_for_should do
12
+ rescued_exception.message
13
+ end
14
+ end
15
+
16
+ matcher :be_routable do
17
+ match_unless_raises ActionController::RoutingError do |path|
18
+ @routing_options = routes.recognize_path(
19
+ path.values.first, :method => path.keys.first
20
+ )
21
+ end
22
+
23
+ failure_message_for_should_not do |path|
24
+ "expected #{path.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,4 +1 @@
1
- require 'rspec/rails/monkey/action_controller/test_case'
2
- require 'rspec/rails/monkey/action_view/test_case'
3
1
  require 'rspec/rails/monkey/action_mailer/test_case'
4
- require 'rspec/rails/monkey/active_support/notifications/fanout'
@@ -1,3 +1,6 @@
1
+ require 'action_controller'
2
+ require 'action_view/testing/resolvers'
3
+
1
4
  module RSpec
2
5
  module Rails
3
6
  module ViewRendering
@@ -21,7 +24,7 @@ module RSpec
21
24
  included do
22
25
  before do
23
26
  @_view_paths = controller.class.view_paths
24
- controller.class.view_paths = [RSpec::Rails::NullResolver.new()] unless
27
+ controller.class.view_paths = [ActionView::NullResolver.new()] unless
25
28
  self.class.render_views?
26
29
  end
27
30
 
@@ -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.12"
8
+ s.version = "2.0.0.beta.13"
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-14}
12
+ s.date = %q{2010-06-23}
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 = [
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "features/matchers/new_record_matcher.feature",
32
32
  "features/model_specs/errors_on.feature",
33
33
  "features/model_specs/transactional_examples.feature",
34
+ "features/routing_specs/be_routable_matcher.feature",
34
35
  "features/step_definitions/model_steps.rb",
35
36
  "features/support/env.rb",
36
37
  "features/view_specs/view_spec.feature",
@@ -74,18 +75,20 @@ Gem::Specification.new do |s|
74
75
  "lib/rspec/rails/example/helper_example_group.rb",
75
76
  "lib/rspec/rails/example/mailer_example_group.rb",
76
77
  "lib/rspec/rails/example/request_example_group.rb",
78
+ "lib/rspec/rails/example/routing_example_group.rb",
77
79
  "lib/rspec/rails/example/view_example_group.rb",
78
80
  "lib/rspec/rails/extensions.rb",
79
81
  "lib/rspec/rails/extensions/active_record/base.rb",
80
82
  "lib/rspec/rails/fixture_support.rb",
81
83
  "lib/rspec/rails/matchers.rb",
84
+ "lib/rspec/rails/matchers/be_a_new.rb",
85
+ "lib/rspec/rails/matchers/have_extension.rb",
86
+ "lib/rspec/rails/matchers/redirect_to.rb",
87
+ "lib/rspec/rails/matchers/render_template.rb",
88
+ "lib/rspec/rails/matchers/routing_spec_matchers.rb",
82
89
  "lib/rspec/rails/mocks.rb",
83
90
  "lib/rspec/rails/monkey.rb",
84
- "lib/rspec/rails/monkey/action_controller/test_case.rb",
85
91
  "lib/rspec/rails/monkey/action_mailer/test_case.rb",
86
- "lib/rspec/rails/monkey/action_view/test_case.rb",
87
- "lib/rspec/rails/monkey/active_support/notifications/fanout.rb",
88
- "lib/rspec/rails/null_resolver.rb",
89
92
  "lib/rspec/rails/version.rb",
90
93
  "lib/rspec/rails/view_assigns.rb",
91
94
  "lib/rspec/rails/view_rendering.rb",
@@ -94,12 +97,14 @@ Gem::Specification.new do |s|
94
97
  "spec/rspec/rails/example/helper_example_group_spec.rb",
95
98
  "spec/rspec/rails/example/mailer_example_group_spec.rb",
96
99
  "spec/rspec/rails/example/request_example_group_spec.rb",
100
+ "spec/rspec/rails/example/routing_example_group_spec.rb",
97
101
  "spec/rspec/rails/example/view_example_group_spec.rb",
98
102
  "spec/rspec/rails/example/view_rendering_spec.rb",
99
103
  "spec/rspec/rails/matchers/be_a_new_spec.rb",
100
104
  "spec/rspec/rails/matchers/errors_on_spec.rb",
101
105
  "spec/rspec/rails/matchers/redirect_to_spec.rb",
102
106
  "spec/rspec/rails/matchers/render_template_spec.rb",
107
+ "spec/rspec/rails/matchers/route_to_spec.rb",
103
108
  "spec/rspec/rails/mocks/ar_classes.rb",
104
109
  "spec/rspec/rails/mocks/mock_model_spec.rb",
105
110
  "spec/rspec/rails/mocks/stub_model_spec.rb",
@@ -113,7 +118,7 @@ Gem::Specification.new do |s|
113
118
  s.homepage = %q{http://github.com/rspec/rspec-rails}
114
119
  s.post_install_message = %q{**************************************************
115
120
 
116
- Thank you for installing rspec-rails-2.0.0.beta.12!
121
+ Thank you for installing rspec-rails-2.0.0.beta.13!
117
122
 
118
123
  This version of rspec-rails only works with
119
124
  versions of rails >= 3.0.0.pre.
@@ -129,18 +134,20 @@ Gem::Specification.new do |s|
129
134
  s.require_paths = ["lib"]
130
135
  s.rubyforge_project = %q{rspec}
131
136
  s.rubygems_version = %q{1.3.6}
132
- s.summary = %q{rspec-rails-2.0.0.beta.12}
137
+ s.summary = %q{rspec-rails-2.0.0.beta.13}
133
138
  s.test_files = [
134
139
  "spec/rspec/rails/example/controller_example_group_spec.rb",
135
140
  "spec/rspec/rails/example/helper_example_group_spec.rb",
136
141
  "spec/rspec/rails/example/mailer_example_group_spec.rb",
137
142
  "spec/rspec/rails/example/request_example_group_spec.rb",
143
+ "spec/rspec/rails/example/routing_example_group_spec.rb",
138
144
  "spec/rspec/rails/example/view_example_group_spec.rb",
139
145
  "spec/rspec/rails/example/view_rendering_spec.rb",
140
146
  "spec/rspec/rails/matchers/be_a_new_spec.rb",
141
147
  "spec/rspec/rails/matchers/errors_on_spec.rb",
142
148
  "spec/rspec/rails/matchers/redirect_to_spec.rb",
143
149
  "spec/rspec/rails/matchers/render_template_spec.rb",
150
+ "spec/rspec/rails/matchers/route_to_spec.rb",
144
151
  "spec/rspec/rails/mocks/ar_classes.rb",
145
152
  "spec/rspec/rails/mocks/mock_model_spec.rb",
146
153
  "spec/rspec/rails/mocks/stub_model_spec.rb",
@@ -153,14 +160,14 @@ Gem::Specification.new do |s|
153
160
  s.specification_version = 3
154
161
 
155
162
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
156
- s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.12"])
163
+ s.add_runtime_dependency(%q<rspec>, ["= 2.0.0.beta.13"])
157
164
  s.add_runtime_dependency(%q<webrat>, [">= 0.7.0"])
158
165
  else
159
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.12"])
166
+ s.add_dependency(%q<rspec>, ["= 2.0.0.beta.13"])
160
167
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
161
168
  end
162
169
  else
163
- s.add_dependency(%q<rspec>, ["= 2.0.0.beta.12"])
170
+ s.add_dependency(%q<rspec>, ["= 2.0.0.beta.13"])
164
171
  s.add_dependency(%q<webrat>, [">= 0.7.0"])
165
172
  end
166
173
  end
@@ -14,7 +14,7 @@ module RSpec::Rails
14
14
 
15
15
  it "provides a controller_path based on the helper module's name" do
16
16
  helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
17
- helper_spec.stub_chain(:running_example, :example_group, :describes).and_return(FoosHelper)
17
+ helper_spec.stub_chain(:example, :example_group, :describes).and_return(FoosHelper)
18
18
  helper_spec.__send__(:_controller_path).should == "foos"
19
19
  end
20
20
 
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ module RSpec::Rails
4
+ describe RoutingExampleGroup do
5
+ it "is included in specs in ./spec/routing" do
6
+ stub_metadata(
7
+ :example_group => {:file_path => "./spec/routing/whatever_spec.rb:15"}
8
+ )
9
+ group = RSpec::Core::ExampleGroup.describe
10
+ group.included_modules.should include(RoutingExampleGroup)
11
+ end
12
+ end
13
+ end
@@ -20,6 +20,9 @@ module RSpec::Rails
20
20
  def render(options={}, local_assigns={}, &block)
21
21
  received << [options, local_assigns, block]
22
22
  end
23
+ def _assigns
24
+ {}
25
+ end
23
26
  end
24
27
  include Local
25
28
  include ViewExampleGroup::InstanceMethods
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
  require "action_controller/test_case"
3
3
 
4
4
  describe "redirect_to" do
5
- include RSpec::Rails::ControllerSpecMatchers
5
+ include RSpec::Rails::Matchers::RedirectTo
6
6
 
7
7
  it "delegates to assert_redirected_to" do
8
8
  self.should_receive(:assert_redirected_to).with("destination")
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "render_template" do
4
- include RSpec::Rails::ControllerSpecMatchers
4
+ include RSpec::Rails::Matchers::RenderTemplate
5
5
 
6
6
  it "uses failure message from render_template" do
7
7
  self.stub!(:assert_template).and_raise(
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ describe "route_to" do
4
+ include RSpec::Rails::RoutingSpecMatchers
5
+
6
+ it "uses failure message from assert_routing" do
7
+ self.stub!(:assert_routing).and_raise(
8
+ Test::Unit::AssertionFailedError.new("this message"))
9
+ expect do
10
+ {"this" => "path"}.should route_to("these" => "options")
11
+ end.to raise_error("this message")
12
+ end
13
+ end
14
+
15
+ describe "be_routable" do
16
+ include RSpec::Rails::RoutingSpecMatchers
17
+ attr_reader :routes
18
+
19
+ before { @routes = double("routes") }
20
+
21
+ context "with should" do
22
+ it "passes if routes recognize the path" do
23
+ routes.stub(:recognize_path) { {} }
24
+ expect do
25
+ {:get => "/a/path"}.should be_routable
26
+ end.to_not raise_error
27
+ end
28
+
29
+ it "fails if routes do not recognize the path" do
30
+ routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
31
+ expect do
32
+ {:get => "/a/path"}.should be_routable
33
+ end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
34
+ end
35
+ end
36
+
37
+ context "with should_not" do
38
+
39
+ it "passes if routes do not recognize the path" do
40
+ routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
41
+ expect do
42
+ {:get => "/a/path"}.should_not be_routable
43
+ end.to_not raise_error
44
+ end
45
+
46
+ it "fails if routes recognize the path" do
47
+ routes.stub(:recognize_path) { {:controller => "foo"} }
48
+ expect do
49
+ {:get => "/a/path"}.should_not be_routable
50
+ end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
51
+ end
52
+ end
53
+ end
@@ -1,31 +1,12 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem "arel", :path => "../../vendor/arel"
4
- gem "rails", :path => "../../vendor/rails"
3
+ gem 'arel', :path => "../../vendor/arel"
4
+ gem 'rails', :path => "../../vendor/rails"
5
5
 
6
6
  gem 'sqlite3-ruby', :require => 'sqlite3'
7
7
 
8
- # Use unicorn as the web server
9
- # gem 'unicorn'
10
-
11
- # Deploy with Capistrano
12
- # gem 'capistrano'
13
-
14
- # To use debugger
15
- # gem 'ruby-debug'
16
-
17
- # Bundle the extra gems:
18
- # gem 'bj'
19
- # gem 'nokogiri', '1.4.1'
20
- # gem 'sqlite3-ruby', :require => 'sqlite3'
21
- # gem 'aws-s3', :require => 'aws/s3'
22
-
23
- # Bundle gems for certain environments:
24
- # gem 'rspec', :group => :test
25
- # group :test do
26
- # gem 'webrat'
27
- # end
28
-
29
- group :test do
30
- gem "rspec-rails", :path => "../../../rspec-rails"
31
- end
8
+ gem "rspec-rails", :path => "../../../rspec-rails"
9
+ gem "rspec", :path => "../../../rspec"
10
+ gem "rspec-core", :path => "../../../rspec-core"
11
+ gem "rspec-expectations", :path => "../../../rspec-expectations"
12
+ gem "rspec-mocks", :path => "../../../rspec-mocks"