rspec-rails 2.0.0.beta.22 → 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 (134) hide show
  1. data/.gitignore +10 -4
  2. data/.rspec +1 -0
  3. data/.travis.yml +10 -0
  4. data/History.md +1 -33
  5. data/License.txt +23 -0
  6. data/{README.markdown → README.md} +27 -7
  7. data/README_DEV.md +43 -0
  8. data/Rakefile +105 -35
  9. data/Thorfile +40 -0
  10. data/Upgrade.md +1 -0
  11. data/features/.nav +34 -0
  12. data/features/Autotest.md +24 -0
  13. data/features/Changelog.md +151 -0
  14. data/features/Generators.md +8 -0
  15. data/features/GettingStarted.md +84 -0
  16. data/features/README.md +58 -0
  17. data/features/Upgrade.md +117 -0
  18. data/features/controller_specs/README.md +45 -0
  19. data/features/controller_specs/anonymous_controller.feature +7 -7
  20. data/features/controller_specs/controller_spec.feature +18 -0
  21. data/features/controller_specs/isolation_from_views.feature +55 -8
  22. data/features/controller_specs/render_views.feature +63 -52
  23. data/features/helper_specs/helper_spec.feature +40 -6
  24. data/features/mailer_specs/url_helpers.feature +4 -4
  25. data/features/matchers/README.md +4 -0
  26. data/features/matchers/new_record_matcher.feature +6 -48
  27. data/features/matchers/redirect_to_matcher.feature +5 -6
  28. data/features/matchers/render_template_matcher.feature +13 -10
  29. data/features/mocks/mock_model.feature +29 -13
  30. data/features/mocks/stub_model.feature +4 -4
  31. data/features/model_specs/README.md +21 -0
  32. data/features/model_specs/errors_on.feature +2 -2
  33. data/features/model_specs/transactional_examples.feature +14 -9
  34. data/features/request_specs/request_spec.feature +49 -0
  35. data/features/routing_specs/README.md +17 -0
  36. data/features/{matchers → routing_specs}/be_routable_matcher.feature +25 -25
  37. data/features/routing_specs/named_routes.feature +18 -0
  38. data/features/routing_specs/route_to_matcher.feature +58 -0
  39. data/features/step_definitions/additional_cli_steps.rb +4 -0
  40. data/features/support/env.rb +14 -6
  41. data/features/view_specs/inferred_controller_path.feature +6 -6
  42. data/features/view_specs/stub_template.feature +51 -0
  43. data/features/view_specs/view_spec.feature +23 -42
  44. data/gemfiles/.bundle/config +2 -0
  45. data/gemfiles/base.rb +58 -0
  46. data/gemfiles/rails-3-0-stable +6 -0
  47. data/gemfiles/rails-3.0.0 +5 -0
  48. data/gemfiles/rails-3.0.1 +5 -0
  49. data/gemfiles/rails-3.0.2 +5 -0
  50. data/gemfiles/rails-3.0.3 +5 -0
  51. data/gemfiles/rails-3.0.4 +5 -0
  52. data/gemfiles/rails-3.0.5 +5 -0
  53. data/gemfiles/rails-3.0.6 +5 -0
  54. data/gemfiles/rails-3.0.7 +5 -0
  55. data/gemfiles/rails-3.1.0.beta1 +5 -0
  56. data/gemfiles/rails-master +7 -0
  57. data/lib/autotest/rails_rspec2.rb +1 -1
  58. data/lib/generators/rspec/controller/controller_generator.rb +4 -4
  59. data/lib/generators/rspec/helper/helper_generator.rb +3 -3
  60. data/lib/generators/rspec/install/install_generator.rb +0 -8
  61. data/lib/generators/rspec/integration/integration_generator.rb +15 -1
  62. data/lib/generators/rspec/integration/templates/request_spec.rb +7 -1
  63. data/lib/generators/rspec/mailer/mailer_generator.rb +2 -2
  64. data/lib/generators/rspec/model/model_generator.rb +1 -1
  65. data/lib/generators/rspec/observer/observer_generator.rb +1 -1
  66. data/lib/generators/rspec/scaffold/scaffold_generator.rb +40 -11
  67. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +90 -58
  68. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +15 -7
  69. data/lib/generators/rspec/scaffold/templates/index_spec.rb +7 -2
  70. data/lib/generators/rspec/scaffold/templates/new_spec.rb +14 -7
  71. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
  72. data/lib/generators/rspec/scaffold/templates/show_spec.rb +7 -2
  73. data/lib/generators/rspec/view/view_generator.rb +1 -1
  74. data/lib/rspec/rails/example/controller_example_group.rb +25 -34
  75. data/lib/rspec/rails/example/helper_example_group.rb +5 -11
  76. data/lib/rspec/rails/example/mailer_example_group.rb +0 -14
  77. data/lib/rspec/rails/example/model_example_group.rb +0 -4
  78. data/lib/rspec/rails/example/rails_example_group.rb +0 -2
  79. data/lib/rspec/rails/example/request_example_group.rb +5 -30
  80. data/lib/rspec/rails/example/routing_example_group.rb +3 -5
  81. data/lib/rspec/rails/example/view_example_group.rb +20 -11
  82. data/lib/rspec/rails/example.rb +31 -1
  83. data/lib/rspec/rails/extensions/active_record/base.rb +28 -32
  84. data/lib/rspec/rails/fixture_support.rb +1 -1
  85. data/lib/rspec/rails/matchers/be_new_record.rb +5 -0
  86. data/lib/rspec/rails/matchers/redirect_to.rb +6 -2
  87. data/lib/rspec/rails/matchers/render_template.rb +5 -1
  88. data/lib/rspec/rails/matchers/routing_matchers.rb +24 -3
  89. data/lib/rspec/rails/matchers.rb +1 -1
  90. data/lib/rspec/rails/mocks.rb +118 -79
  91. data/lib/rspec/rails/module_inclusion.rb +17 -0
  92. data/lib/rspec/rails/tasks/rspec.rake +1 -1
  93. data/lib/rspec/rails/vendor/capybara.rb +29 -0
  94. data/lib/rspec/rails/vendor/webrat.rb +33 -0
  95. data/lib/rspec/rails/version.rb +1 -1
  96. data/lib/rspec/rails/view_assigns.rb +23 -4
  97. data/lib/rspec/rails/view_rendering.rb +50 -13
  98. data/lib/rspec/rails.rb +7 -10
  99. data/lib/rspec-rails.rb +4 -2
  100. data/rspec-rails.gemspec +11 -39
  101. data/spec/autotest/rails_rspec2_spec.rb +25 -14
  102. data/spec/rspec/rails/configuration_spec.rb +26 -0
  103. data/spec/rspec/rails/deprecations_spec.rb +18 -0
  104. data/spec/rspec/rails/example/controller_example_group_spec.rb +47 -5
  105. data/spec/rspec/rails/example/helper_example_group_spec.rb +19 -1
  106. data/spec/rspec/rails/example/request_example_group_spec.rb +2 -0
  107. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
  108. data/spec/rspec/rails/extensions/active_record/records_spec.rb +9 -0
  109. data/spec/rspec/rails/matchers/be_new_record_spec.rb +17 -0
  110. data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
  111. data/spec/rspec/rails/matchers/redirect_to_spec.rb +67 -8
  112. data/spec/rspec/rails/matchers/render_template_spec.rb +67 -10
  113. data/spec/rspec/rails/matchers/route_to_spec.rb +77 -31
  114. data/spec/rspec/rails/mocks/ar_classes.rb +17 -25
  115. data/spec/rspec/rails/mocks/mock_model_spec.rb +50 -13
  116. data/spec/rspec/rails/mocks/stub_model_spec.rb +121 -67
  117. data/spec/rspec/rails/view_rendering_spec.rb +105 -0
  118. data/spec/spec_helper.rb +0 -22
  119. data/spec/support/matchers.rb +9 -0
  120. data/templates/generate_stuff.rb +10 -2
  121. data/templates/run_specs.rb +2 -2
  122. metadata +141 -79
  123. data/Gemfile +0 -24
  124. data/Gotchas.markdown +0 -14
  125. data/Upgrade.markdown +0 -31
  126. data/autotest/discover.rb +0 -1
  127. data/features/README.markdown +0 -12
  128. data/features/controller_specs/readers.feature +0 -18
  129. data/features/routing_specs/access_to_named_routes.feature +0 -15
  130. data/lib/generators/rspec/install/templates/autotest/discover.rb +0 -2
  131. data/lib/rspec/rails/browser_simulators.rb +0 -30
  132. data/spec/rspec/rails/example/view_rendering_spec.rb +0 -110
  133. data/specs.watchr +0 -59
  134. data/templates/Gemfile +0 -18
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'capybara/rspec'
3
+ rescue LoadError
4
+ end
5
+
6
+ begin
7
+ require 'capybara/rails'
8
+ rescue LoadError
9
+ end
10
+
11
+ RSpec.configure do |c|
12
+ if defined?(Capybara::RSpecMatchers)
13
+ c.include Capybara::RSpecMatchers, :type => :view
14
+ c.include Capybara::RSpecMatchers, :type => :helper
15
+ c.include Capybara::RSpecMatchers, :type => :mailer
16
+ c.include Capybara::RSpecMatchers, :type => :controller
17
+ end
18
+
19
+ if defined?(Capybara::DSL)
20
+ c.include Capybara::DSL, :type => :controller
21
+ end
22
+
23
+ unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
24
+ if defined?(Capybara)
25
+ c.include Capybara, :type => :request
26
+ c.include Capybara, :type => :controller
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ begin
2
+ require 'webrat'
3
+ rescue LoadError
4
+ end
5
+
6
+ RSpec.configure do |c|
7
+ if defined?(Webrat)
8
+ c.include Webrat::Matchers, :type => :request
9
+ c.include Webrat::Matchers, :type => :controller
10
+ c.include Webrat::Matchers, :type => :view
11
+ c.include Webrat::Matchers, :type => :helper
12
+ c.include Webrat::Matchers, :type => :mailer
13
+
14
+ c.include Webrat::Methods, :type => :request
15
+ c.include Webrat::Methods, :type => :controller
16
+
17
+ module RequestInstanceMethods
18
+ def last_response
19
+ @response
20
+ end
21
+ end
22
+
23
+ c.include RequestInstanceMethods, :type => :request
24
+
25
+ c.before :type => :controller do
26
+ Webrat.configure {|c| c.mode = :rails}
27
+ end
28
+
29
+ c.before :type => :request do
30
+ Webrat.configure {|c| c.mode = :rack}
31
+ end
32
+ end
33
+ end
@@ -1,7 +1,7 @@
1
1
  module RSpec # :nodoc:
2
2
  module Rails # :nodoc:
3
3
  module Version # :nodoc:
4
- STRING = '2.0.0.beta.22'
4
+ STRING = '2.6.0'
5
5
  end
6
6
  end
7
7
  end
@@ -13,16 +13,35 @@ module RSpec
13
13
  _encapsulated_assigns[key] = value
14
14
  end
15
15
 
16
- private
17
-
18
- def _encapsulated_assigns
19
- @_encapsulated_assigns ||= {}
16
+ def view_assigns
17
+ begin
18
+ # TODO: _assigns was deprecated in favor of view_assigns after
19
+ # Rails-3.0.0 was released. Since we are not able to predict when
20
+ # the _assigns/view_assigns patch will be released (I thought it
21
+ # would have been in 3.0.1, but 3.0.1 bypassed this change for a
22
+ # security fix), this bit ensures that we do the right thing without
23
+ # knowing anything about the Rails version we are dealing with.
24
+ #
25
+ # Once that change _is_ released, this can be changed to something
26
+ # that checks for the Rails version when the module is being
27
+ # interpreted, as it was before commit dd0095.
28
+ super.merge(_encapsulated_assigns)
29
+ rescue
30
+ _assigns
31
+ end
20
32
  end
21
33
 
22
34
  def _assigns
23
35
  super.merge(_encapsulated_assigns)
24
36
  end
37
+
38
+ private
39
+
40
+ def _encapsulated_assigns
41
+ @_encapsulated_assigns ||= {}
42
+ end
25
43
  end
44
+
26
45
  end
27
46
  end
28
47
  end
@@ -1,42 +1,63 @@
1
1
  require 'action_view/testing/resolvers'
2
2
 
3
+ RSpec.configure do |config|
4
+ config.add_setting :render_views, :default => false
5
+
6
+ # TODO - rspec-core needs a way to define a setting that works like this in
7
+ # one go
8
+ def config.render_views
9
+ settings[:render_views] = true
10
+ end
11
+
12
+ def config.render_views?
13
+ settings[:render_views]
14
+ end
15
+ end
16
+
3
17
  module RSpec
4
18
  module Rails
5
19
  module ViewRendering
6
20
  extend ActiveSupport::Concern
7
21
 
22
+ attr_accessor :controller
23
+
8
24
  module ClassMethods
9
25
  def metadata_for_rspec_rails
10
- metadata[:rspec_rails] ||= {}
26
+ metadata[:rspec_rails] = metadata[:rspec_rails] ? metadata[:rspec_rails].dup : {}
11
27
  end
12
28
 
13
29
  # See RSpec::Rails::ControllerExampleGroup
14
- def render_views
15
- metadata_for_rspec_rails[:render_views] = true
30
+ def render_views(true_or_false=true)
31
+ metadata_for_rspec_rails[:render_views] = true_or_false
32
+ end
33
+
34
+ def integrate_views
35
+ RSpec.deprecate("integrate_views","render_views")
36
+ render_views
16
37
  end
17
38
 
18
39
  def render_views?
19
- !!metadata_for_rspec_rails[:render_views]
40
+ metadata_for_rspec_rails[:render_views] || RSpec.configuration.render_views?
20
41
  end
21
42
  end
22
43
 
23
44
  module InstanceMethods
24
45
  def render_views?
25
- self.class.render_views? || !@controller.class.respond_to?(:view_paths)
46
+ self.class.render_views? || !controller.class.respond_to?(:view_paths)
26
47
  end
27
48
  end
28
49
 
29
50
  # Delegates find_all to the submitted path set and then returns templates
30
51
  # with modified source
31
- class PathSetDelegatorResolver < ::ActionView::Resolver
32
- attr_reader :path_set
52
+ class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
53
+ attr_reader :original_path_set
33
54
 
34
- def initialize(path_set)
35
- @path_set = path_set
55
+ def initialize(original_path_set)
56
+ @original_path_set = original_path_set
36
57
  end
37
58
 
38
59
  def find_all(*args)
39
- path_set.find_all(*args).collect do |template|
60
+ original_path_set.find_all(*args).collect do |template|
40
61
  ::ActionView::Template.new(
41
62
  "",
42
63
  template.identifier,
@@ -50,17 +71,33 @@ module RSpec
50
71
  end
51
72
  end
52
73
 
74
+ module EmptyTemplates
75
+ def prepend_view_path(new_path)
76
+ lookup_context.view_paths.unshift(*_path_decorator(new_path))
77
+ end
78
+
79
+ def append_view_path(new_path)
80
+ lookup_context.view_paths.push(*_path_decorator(new_path))
81
+ end
82
+
83
+ private
84
+ def _path_decorator(path)
85
+ EmptyTemplatePathSetDecorator.new(::ActionView::Base::process_view_paths(path))
86
+ end
87
+ end
88
+
53
89
  included do
54
90
  before do
55
91
  unless render_views?
56
- @_path_set_delegator_resolver = PathSetDelegatorResolver.new(@controller.class.view_paths)
57
- @controller.class.view_paths = ::ActionView::PathSet.new.push(@_path_set_delegator_resolver)
92
+ @_empty_view_path_set_delegator = EmptyTemplatePathSetDecorator.new(controller.class.view_paths)
93
+ controller.class.view_paths = ::ActionView::PathSet.new.push(@_empty_view_path_set_delegator)
94
+ controller.extend(EmptyTemplates)
58
95
  end
59
96
  end
60
97
 
61
98
  after do
62
99
  unless render_views?
63
- @controller.class.view_paths = @_path_set_delegator_resolver.path_set
100
+ controller.class.view_paths = @_empty_view_path_set_delegator.original_path_set
64
101
  end
65
102
  end
66
103
  end
data/lib/rspec/rails.rb CHANGED
@@ -1,14 +1,10 @@
1
- module RSpec
2
- module Rails
3
- class << self
4
- def using_active_record?
5
- ::Rails.configuration.generators.options[:rails][:orm] == :active_record
6
- end
7
- end
8
- end
1
+ require 'rspec/core'
2
+
3
+ RSpec::configure do |c|
4
+ c.backtrace_clean_patterns << /vendor\//
5
+ c.backtrace_clean_patterns << /lib\/rspec\/rails/
9
6
  end
10
7
 
11
- require 'rspec/core'
12
8
  require 'rspec/rails/extensions'
13
9
  require 'rspec/rails/view_rendering'
14
10
  require 'rspec/rails/adapters'
@@ -16,5 +12,6 @@ require 'rspec/rails/matchers'
16
12
  require 'rspec/rails/fixture_support'
17
13
  require 'rspec/rails/mocks'
18
14
  require 'rspec/rails/module_inclusion'
19
- require 'rspec/rails/browser_simulators'
20
15
  require 'rspec/rails/example'
16
+ require 'rspec/rails/vendor/capybara'
17
+ require 'rspec/rails/vendor/webrat'
data/lib/rspec-rails.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  class Railtie < ::Rails::Railtie
4
- config.generators.integration_tool :rspec
5
- config.generators.test_framework :rspec
4
+ # Rails-3.0.1 requires config.app_generators instead of 3.0.0's config.generators
5
+ generators = config.respond_to?(:app_generators) ? config.app_generators : config.generators
6
+ generators.integration_tool :rspec
7
+ generators.test_framework :rspec
6
8
 
7
9
  rake_tasks do
8
10
  load "rspec/rails/tasks/rspec.rake"
data/rspec-rails.gemspec CHANGED
@@ -6,8 +6,8 @@ Gem::Specification.new do |s|
6
6
  s.name = "rspec-rails"
7
7
  s.version = RSpec::Rails::Version::STRING
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["David Chelimsky", "Chad Humphries"]
10
- s.email = "dchelimsky@gmail.com;chad.humphries@gmail.com"
9
+ s.authors = ["David Chelimsky"]
10
+ s.email = "dchelimsky@gmail.com"
11
11
  s.homepage = "http://github.com/rspec/rspec-rails"
12
12
  s.summary = "rspec-rails-#{RSpec::Rails::Version::STRING}"
13
13
  s.description = "RSpec-2 for Rails-3"
@@ -18,45 +18,17 @@ Gem::Specification.new do |s|
18
18
  s.files = `git ls-files`.split("\n")
19
19
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
20
20
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
- s.extra_rdoc_files = [ "README.markdown" ]
21
+ s.extra_rdoc_files = [ "README.md" ]
22
22
  s.rdoc_options = ["--charset=UTF-8"]
23
23
  s.require_path = "lib"
24
24
 
25
- s.post_install_message = %Q{**************************************************
26
-
27
- Thank you for installing #{s.summary}!
28
-
29
- This version of rspec-rails only works with versions of rails >= 3.0.0.beta.4.
30
-
31
- To configure your app to use rspec-rails, add a declaration to your Gemfile.
32
- If you are using Bundler's grouping feature in your Gemfile, be sure to include
33
- rspec-rails in the :development group as well as the :test group so that you
34
- can access its generators and rake tasks.
35
-
36
- group :development, :test do
37
- gem "rspec-rails", ">= #{RSpec::Rails::Version::STRING}"
38
- end
39
-
40
- Be sure to run the following command in each of your Rails apps if you're
41
- upgrading:
42
-
43
- script/rails generate rspec:install
44
-
45
- Even if you've run it before, this ensures that you have the latest updates
46
- to spec/spec_helper.rb and any other support files.
47
-
48
- Previous versions of rspec-rails-2.0.0.beta installed files that are no
49
- longer being used, so please remove these files if you have them:
50
-
51
- lib/tasks/rspec.rake
52
- config/initializers/rspec_generator.rb
53
-
54
- Lastly, be sure to look at Upgrade.markdown to see what might have changed
55
- since the last release.
56
-
57
- **************************************************
58
- }
59
-
60
- s.add_runtime_dependency "rspec", RSpec::Rails::Version::STRING
25
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0"])
26
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0"])
27
+ s.add_runtime_dependency(%q<railties>, ["~> 3.0"])
28
+ if RSpec::Rails::Version::STRING =~ /[a-zA-Z]+/
29
+ s.add_runtime_dependency "rspec", "= #{RSpec::Rails::Version::STRING}"
30
+ else
31
+ s.add_runtime_dependency "rspec", "~> #{RSpec::Rails::Version::STRING.split('.')[0..1].concat(['0']).join('.')}"
32
+ end
61
33
  end
62
34
 
@@ -2,24 +2,35 @@ require "spec_helper"
2
2
  require "autotest/rails_rspec2"
3
3
 
4
4
  describe Autotest::RailsRspec2 do
5
- before(:each) do
6
- rails_rspec2_autotest = Autotest::RailsRspec2.new
7
- @re = rails_rspec2_autotest.exceptions
8
- end
9
5
 
10
- it "should match './log/test.log'" do
11
- @re.should match('./log/test.log')
12
- end
6
+ let(:rails_rspec2_autotest) { Autotest::RailsRspec2.new }
13
7
 
14
- it "should match 'log/test.log'" do
15
- @re.should match('log/test.log')
16
- end
8
+ describe 'exceptions' do
9
+ let(:exceptions_regexp) { rails_rspec2_autotest.exceptions }
10
+
11
+ it "should match './log/test.log'" do
12
+ exceptions_regexp.should match('./log/test.log')
13
+ end
17
14
 
18
- it "should not match './spec/models/user_spec.rb'" do
19
- @re.should_not match('./spec/models/user_spec.rb')
15
+ it "should match 'log/test.log'" do
16
+ exceptions_regexp.should match('log/test.log')
17
+ end
18
+
19
+ it "should not match './spec/models/user_spec.rb'" do
20
+ exceptions_regexp.should_not match('./spec/models/user_spec.rb')
21
+ end
22
+
23
+ it "should not match 'spec/models/user_spec.rb'" do
24
+ exceptions_regexp.should_not match('spec/models/user_spec.rb')
25
+ end
20
26
  end
21
27
 
22
- it "should not match 'spec/models/user_spec.rb'" do
23
- @re.should_not match('spec/models/user_spec.rb')
28
+ describe 'mappings' do
29
+ it 'runs model specs when support files change' do
30
+ rails_rspec2_autotest.find_order = %w(spec/models/user_spec.rb spec/support/blueprints.rb)
31
+ rails_rspec2_autotest.test_files_for('spec/support/blueprints.rb').should(
32
+ include('spec/models/user_spec.rb'))
33
+ end
24
34
  end
35
+
25
36
  end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe "configuration" do
4
+ before do
5
+ @orig_render_views = RSpec.configuration.render_views?
6
+ end
7
+
8
+ after do
9
+ RSpec.configuration.render_views = @orig_render_views
10
+ end
11
+
12
+ describe "#render_views?" do
13
+ it "is false by default" do
14
+ RSpec.configuration.render_views?.should be_false
15
+ end
16
+ end
17
+
18
+ describe "#render_views" do
19
+ it "sets render_views? to return true" do
20
+ RSpec.configuration.render_views = false
21
+ RSpec.configuration.render_views
22
+
23
+ RSpec.configuration.render_views?.should be_true
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "rspec-rails-2 deprecations" do
4
+ context "controller specs" do
5
+ describe "::integrate_views" do
6
+ let(:group) do
7
+ RSpec::Core::ExampleGroup.describe do
8
+ include RSpec::Rails::ControllerExampleGroup
9
+ end
10
+ end
11
+
12
+ it "is deprecated" do
13
+ RSpec.should_receive(:deprecate)
14
+ group.integrate_views
15
+ end
16
+ end
17
+ end
18
+ end
@@ -5,18 +5,60 @@ module RSpec::Rails
5
5
  it { should be_included_in_files_in('./spec/controllers/') }
6
6
  it { should be_included_in_files_in('.\\spec\\controllers\\') }
7
7
 
8
- it "includes routing matchers" do
9
- group = RSpec::Core::ExampleGroup.describe do
8
+ let(:group) do
9
+ RSpec::Core::ExampleGroup.describe do
10
10
  include ControllerExampleGroup
11
11
  end
12
+ end
13
+
14
+ it "includes routing matchers" do
12
15
  group.included_modules.should include(RSpec::Rails::Matchers::RoutingMatchers)
13
16
  end
14
17
 
15
18
  it "adds :type => :controller to the metadata" do
16
- group = RSpec::Core::ExampleGroup.describe do
17
- include ControllerExampleGroup
18
- end
19
19
  group.metadata[:type].should eq(:controller)
20
20
  end
21
+
22
+ context "with implicit subject" do
23
+ it "uses the controller as the subject" do
24
+ controller = double('controller')
25
+ example = group.new
26
+ example.stub(:controller => controller)
27
+ example.subject.should == controller
28
+ end
29
+ end
30
+
31
+ describe "with explicit subject" do
32
+ it "should use the specified subject instead of the controller" do
33
+ group.subject { 'explicit' }
34
+ example = group.new
35
+ example.subject.should == 'explicit'
36
+ end
37
+ end
38
+
39
+ describe "with anonymous controller" do
40
+ before do
41
+ group.class_eval do
42
+ controller(Class.new) { }
43
+ end
44
+ end
45
+
46
+ it "delegates named route helpers to the underlying controller" do
47
+ controller = double('controller')
48
+ controller.stub(:foos_url).and_return('http://test.host/foos')
49
+
50
+ example = group.new
51
+ example.stub(:controller => controller)
52
+
53
+ # As in the routing example spec, this is pretty invasive, but not sure
54
+ # how to do it any other way as the correct operation relies on before
55
+ # hooks
56
+ routes = ActionDispatch::Routing::RouteSet.new
57
+ routes.draw { resources :foos }
58
+ example.instance_variable_set(:@orig_routes, routes)
59
+
60
+ example.foos_url.should eq('http://test.host/foos')
61
+ end
62
+ end
21
63
  end
22
64
  end
@@ -24,12 +24,30 @@ module RSpec::Rails
24
24
  describe "#helper" do
25
25
  it "returns the instance of AV::Base provided by AV::TC::Behavior" do
26
26
  helper_spec = Object.new.extend HelperExampleGroup::InstanceMethods
27
- helper_spec.should_receive(:_assigns)
27
+ helper_spec.should_receive(:view_assigns)
28
28
  av_tc_b_view = double('_view')
29
29
  av_tc_b_view.should_receive(:assign)
30
30
  helper_spec.stub(:_view) { av_tc_b_view }
31
31
  helper_spec.helper.should eq(av_tc_b_view)
32
32
  end
33
+
34
+ before do
35
+ Object.const_set(:ApplicationHelper, Module.new)
36
+ end
37
+
38
+ after do
39
+ Object.__send__(:remove_const, :ApplicationHelper)
40
+ end
41
+
42
+ it "includes ApplicationHelper" do
43
+ group = RSpec::Core::ExampleGroup.describe do
44
+ include HelperExampleGroup
45
+ def _view
46
+ ActionView::Base.new
47
+ end
48
+ end
49
+ group.new.helper.should be_kind_of(ApplicationHelper)
50
+ end
33
51
  end
34
52
  end
35
53
 
@@ -3,7 +3,9 @@ require "spec_helper"
3
3
  module RSpec::Rails
4
4
  describe RequestExampleGroup do
5
5
  it { should be_included_in_files_in('./spec/requests/') }
6
+ it { should be_included_in_files_in('./spec/integration/') }
6
7
  it { should be_included_in_files_in('.\\spec\\requests\\') }
8
+ it { should be_included_in_files_in('.\\spec\\integration\\') }
7
9
 
8
10
  it "adds :type => :request to the metadata" do
9
11
  group = RSpec::Core::ExampleGroup.describe do
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe "errors_on" do
4
+ let(:klass) do
5
+ Class.new do
6
+ include ActiveModel::Validations
7
+ end
8
+ end
9
+
10
+ it "calls valid?" do
11
+ model = klass.new
12
+ model.should_receive(:valid?)
13
+ model.errors_on(:foo)
14
+ end
15
+
16
+ it "returns the errors on that attribute" do
17
+ model = klass.new
18
+ model.stub(:errors) do
19
+ { :foo => ['a', 'b'] }
20
+ end
21
+ model.errors_on(:foo).should eq(['a','b'])
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe "records" do
4
+ it "delegates to find(:all)" do
5
+ klass = Class.new(ActiveRecord::Base)
6
+ klass.should_receive(:find).with(:all)
7
+ klass.records
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe "be_new_record" do
4
+ context "un-persisted record" do
5
+ it "passes" do
6
+ record = double('record', :persisted? => false)
7
+ record.should be_new_record
8
+ end
9
+ end
10
+
11
+ context "persisted record" do
12
+ it "fails" do
13
+ record = double('record', :persisted? => true)
14
+ record.should_not be_new_record
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe "be_routable" do
4
+ include RSpec::Rails::Matchers::RoutingMatchers
5
+ attr_reader :routes
6
+
7
+ before { @routes = double("routes") }
8
+
9
+ context "with should" do
10
+ it "passes if routes recognize the path" do
11
+ routes.stub(:recognize_path) { {} }
12
+ expect do
13
+ {:get => "/a/path"}.should be_routable
14
+ end.to_not raise_error
15
+ end
16
+
17
+ it "fails if routes do not recognize the path" do
18
+ routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
19
+ expect do
20
+ {:get => "/a/path"}.should be_routable
21
+ end.to raise_error(/expected \{:get=>"\/a\/path"\} to be routable/)
22
+ end
23
+ end
24
+
25
+ context "with should_not" do
26
+
27
+ it "passes if routes do not recognize the path" do
28
+ routes.stub(:recognize_path) { raise ActionController::RoutingError.new('ignore') }
29
+ expect do
30
+ {:get => "/a/path"}.should_not be_routable
31
+ end.to_not raise_error
32
+ end
33
+
34
+ it "fails if routes recognize the path" do
35
+ routes.stub(:recognize_path) { {:controller => "foo"} }
36
+ expect do
37
+ {:get => "/a/path"}.should_not be_routable
38
+ end.to raise_error(/expected \{:get=>"\/a\/path"\} not to be routable, but it routes to \{:controller=>"foo"\}/)
39
+ end
40
+ end
41
+ end