Permalink
Browse files

Upgraded rspec and rspec-rails for Rails 2.1

  • Loading branch information...
1 parent 1354686 commit e3748acda0788f3af873e83fb2fdc853975acc83 @iamjwc iamjwc committed Jun 7, 2008
Showing with 1,205 additions and 332 deletions.
  1. +14 −0 doc/specs.txt
  2. +6 −0 vendor/plugins/rspec-rails/CHANGES
  3. +17 −2 vendor/plugins/rspec-rails/generators/rspec/templates/script/spec_server
  4. +1 −1 vendor/plugins/rspec-rails/generators/rspec_controller/templates/controller_spec.rb
  5. +1 −1 vendor/plugins/rspec-rails/generators/rspec_controller/templates/helper_spec.rb
  6. +2 −2 vendor/plugins/rspec-rails/generators/rspec_controller/templates/view_spec.rb
  7. +1 −1 vendor/plugins/rspec-rails/generators/rspec_model/templates/model_spec.rb
  8. +2 −2 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/controller_spec.rb
  9. +1 −1 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/edit_erb_spec.rb
  10. +1 −1 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/helper_spec.rb
  11. +1 −1 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/index_erb_spec.rb
  12. +1 −1 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/new_erb_spec.rb
  13. +2 −2 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/routing_spec.rb
  14. +1 −1 vendor/plugins/rspec-rails/generators/rspec_scaffold/templates/show_erb_spec.rb
  15. +3 −3 vendor/plugins/rspec-rails/lib/spec/rails.rb
  16. +29 −34 vendor/plugins/rspec-rails/lib/spec/rails/example/controller_example_group.rb
  17. +3 −1 vendor/plugins/rspec-rails/lib/spec/rails/example/rails_example_group.rb
  18. +1 −1 vendor/plugins/rspec-rails/lib/spec/rails/example/render_observer.rb
  19. +6 −1 vendor/plugins/rspec-rails/lib/spec/rails/extensions/spec/example/configuration.rb
  20. +1 −1 vendor/plugins/rspec-rails/lib/spec/rails/version.rb
  21. +1 −0 vendor/plugins/rspec-rails/spec/rails/example/controller_spec_spec.rb
  22. +23 −0 vendor/plugins/rspec-rails/spec/rails/matchers/assert_select_spec.rb
  23. +2 −1 vendor/plugins/rspec-rails/spec/rails/mocks/stub_model_spec.rb
  24. +8 −0 vendor/plugins/rspec-rails/spec/rails/sample_modified_fixture.rb
  25. +3 −2 vendor/plugins/rspec-rails/spec/rails/sample_spec.rb
  26. +34 −27 vendor/plugins/rspec-rails/spec/rails/spec_server_spec.rb
  27. +12 −0 vendor/plugins/rspec/CHANGES
  28. +31 −37 vendor/plugins/rspec/Rakefile
  29. +1 −0 vendor/plugins/rspec/examples/pure/partial_mock_example.rb
  30. +1 −1 vendor/plugins/rspec/examples/stories/game-of-life/behaviour/everything.rb
  31. +17 −17 ...s/rspec/examples/stories/game-of-life/behaviour/stories/CellsWithMoreThanThreeNeighboursDie.story
  32. +1 −1 vendor/plugins/rspec/lib/autotest/rspec.rb
  33. +10 −9 vendor/plugins/rspec/lib/spec.rb
  34. +1 −0 vendor/plugins/rspec/lib/spec/adapters.rb
  35. +26 −0 vendor/plugins/rspec/lib/spec/adapters/ruby_engine.rb
  36. +8 −0 vendor/plugins/rspec/lib/spec/adapters/ruby_engine/mri.rb
  37. +8 −0 vendor/plugins/rspec/lib/spec/adapters/ruby_engine/rubinius.rb
  38. +1 −1 vendor/plugins/rspec/lib/spec/example/example_group_methods.rb
  39. +1 −1 vendor/plugins/rspec/lib/spec/matchers/change.rb
  40. +1 −1 vendor/plugins/rspec/lib/spec/mocks.rb
  41. +1 −0 vendor/plugins/rspec/lib/spec/mocks/extensions.rb
  42. +15 −0 vendor/plugins/rspec/lib/spec/mocks/framework.rb
  43. +4 −0 vendor/plugins/rspec/lib/spec/mocks/mock.rb
  44. +14 −0 vendor/plugins/rspec/lib/spec/mocks/proxy.rb
  45. +18 −26 vendor/plugins/rspec/lib/spec/rake/spectask.rb
  46. +3 −4 vendor/plugins/rspec/lib/spec/runner.rb
  47. +0 −6 vendor/plugins/rspec/lib/spec/runner/formatter/failing_example_groups_formatter.rb
  48. +13 −13 vendor/plugins/rspec/lib/spec/runner/formatter/html_formatter.rb
  49. +65 −0 vendor/plugins/rspec/lib/spec/runner/formatter/nested_text_formatter.rb
  50. +1 −0 vendor/plugins/rspec/lib/spec/runner/option_parser.rb
  51. +2 −0 vendor/plugins/rspec/lib/spec/runner/options.rb
  52. +6 −0 vendor/plugins/rspec/lib/spec/story/runner/scenario_runner.rb
  53. +14 −0 vendor/plugins/rspec/lib/spec/story/runner/story_mediator.rb
  54. +20 −0 vendor/plugins/rspec/lib/spec/story/runner/story_parser.rb
  55. +40 −28 vendor/plugins/rspec/lib/spec/story/step.rb
  56. +6 −2 vendor/plugins/rspec/lib/spec/story/world.rb
  57. +2 −2 vendor/plugins/rspec/lib/spec/version.rb
  58. +2 −0 vendor/plugins/rspec/plugins/mock_frameworks/rspec.rb
  59. +14 −2 vendor/plugins/rspec/spec/autotest/rspec_spec.rb
  60. +10 −0 vendor/plugins/rspec/spec/spec/adapters/ruby_engine_spec.rb
  61. +8 −0 vendor/plugins/rspec/spec/spec/mocks/mock_spec.rb
  62. +36 −0 vendor/plugins/rspec/spec/spec/mocks/partial_mock_spec.rb
  63. +333 −0 vendor/plugins/rspec/spec/spec/runner/formatter/nested_text_formatter_spec.rb
  64. +106 −77 vendor/plugins/rspec/spec/spec/runner/formatter/specdoc_formatter_spec.rb
  65. +10 −0 vendor/plugins/rspec/spec/spec/runner/option_parser_spec.rb
  66. +10 −4 vendor/plugins/rspec/spec/spec/runner/spec_parser_spec.rb
  67. +25 −2 vendor/plugins/rspec/spec/spec/story/runner/scenario_runner_spec.rb
  68. +10 −0 vendor/plugins/rspec/spec/spec/story/runner/story_mediator_spec.rb
  69. +23 −6 vendor/plugins/rspec/spec/spec/story/runner/story_parser_spec.rb
  70. +34 −3 vendor/plugins/rspec/spec/spec/story/step_spec.rb
  71. +1 −1 vendor/plugins/rspec/spec/spec/story/world_spec.rb
  72. +1 −1 vendor/plugins/rspec/stories/all.rb
  73. +7 −0 vendor/plugins/rspec/stories/mock_framework_integration/stories.rb
  74. +9 −0 vendor/plugins/rspec/stories/mock_framework_integration/use_flexmock.story
  75. +18 −0 vendor/plugins/rspec/stories/resources/spec/spec_with_flexmock.rb
  76. +22 −0 vendor/plugins/rspec/stories/stories/multiline_steps.story
  77. +12 −0 vendor/plugins/rspec/stories/stories/steps/multiline_steps.rb
  78. +6 −0 vendor/plugins/rspec/stories/stories/stories.rb
View
@@ -1,5 +1,17 @@
(in /Users/iamjwc/programming/craig/rails-base)
+Spec::Rails::Example::RailsExampleGroup
+
+Spec::Rails::Example::ModelExampleGroup
+
+Spec::Rails::Example::FunctionalExampleGroup
+
+Spec::Rails::Example::ControllerExampleGroup
+
+Spec::Rails::Example::HelperExampleGroup
+
+Spec::Rails::Example::ViewExampleGroup
+
SessionController
- logins and redirects
- fails login and does not redirect
@@ -34,6 +46,8 @@ UserController after logging in
- should allow a user to change their password if they supplied two matching passwords
- should not allow a user to change their password if they supplied two different passwords
+UsersController
+
UsersController when logged in as an admin
- should display a list of the users
- should be able to create new users
@@ -1,3 +1,8 @@
+== Version 1.1.5
+
+* Add conditional so Rails 2.1.0 doesn't warn about cache_template_extensions (patch from James Herdman)
+* Fixed stub_model examples to work with Rails 2.1.0 (the code was fine, just the spec needed patching)
+
== Version 1.1.4
Maintenance release.
@@ -18,3 +23,4 @@ Maintenance release.
* Applied patch from Wincent Colaiuta to invert sense of "spec --diff". Closes #281.
* Allow any type of render in view specs. Closes #57.
* Applied patch from Ian White to get rspec working with edge rails (8804). Closes #271.
+* Applied patch from Jon Strother to have spec_server reload fixtures. Closes #344.
@@ -22,20 +22,29 @@ module Spec
active_connections.delete(name)
end
end
- end
+ end
if ActionController.const_defined?(:Dispatcher)
dispatcher = ::ActionController::Dispatcher.new($stdout)
- dispatcher.cleanup_application(true)
+ dispatcher.cleanup_application
elsif ::Dispatcher.respond_to?(:reset_application!)
::Dispatcher.reset_application!
else
raise "Application reloading failed"
end
+ if Object.const_defined?(:Fixtures) && Fixtures.respond_to?(:reset_cache)
+ Fixtures.reset_cache
+ end
+
::Dependencies.mechanism = :load
require_dependency('application.rb') unless Object.const_defined?(:ApplicationController)
load File.dirname(__FILE__) + '/../spec/spec_helper.rb'
+ if in_memory_database?
+ load "#{RAILS_ROOT}/db/schema.rb" # use db agnostic schema by default
+ ActiveRecord::Migrator.up('db/migrate') # use migrations
+ end
+
::Spec::Runner::CommandLine.run(
::Spec::Runner::OptionParser.parse(
argv,
@@ -44,6 +53,12 @@ module Spec
)
)
end
+
+ def in_memory_database?
+ ENV["RAILS_ENV"] == "test" and
+ ::ActiveRecord::Base.connection.class.to_s == "ActiveRecord::ConnectionAdapters::SQLite3Adapter" and
+ ::Rails::Configuration.new.database_configuration['test']['database'] == ':memory:'
+ end
end
end
end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= class_name %>Controller do
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= class_name %>Helper do
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= class_name.underscore %>/<%= action %>" do
before(:each) do
@@ -7,6 +7,6 @@
#Delete this example and add some real ones or delete this file
it "should tell you where to find the file" do
- response.should have_tag('p', /Find me in app\/views\/<%= class_name.underscore %>\/<%= action %>/)
+ response.should have_tag('p', %r[Find me in app/views/<%= class_name.underscore %>/<%= action %>])
end
end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= class_name %> do
before(:each) do
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_class_name %>Controller do
describe "handling GET /<%= table_name %>" do
@@ -310,4 +310,4 @@ def do_delete
response.should redirect_to(<%= table_name %>_url)
end
end
-end
+end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/edit.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_class_name %>Helper do
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/index.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/new.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
describe <%= controller_class_name %>Controller do
describe "route generation" do
@@ -58,4 +58,4 @@
params_from(:delete, "/<%= table_name %>/1").should == {:controller => "<%= table_name %>", :action => "destroy", :id => "1"}
end
end
-end
+end
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper')
describe "/<%= table_name %>/show.<%= default_file_extension %>" do
include <%= controller_class_name %>Helper
@@ -8,11 +8,11 @@
require 'spec'
-require 'spec/rails/extensions'
-require 'spec/rails/example'
-require 'spec/rails/version'
require 'spec/rails/matchers'
require 'spec/rails/mocks'
+require 'spec/rails/example'
+require 'spec/rails/extensions'
+require 'spec/rails/version'
module Spec
# = Spec::Rails
@@ -212,43 +212,29 @@ def render(options=nil, deprecated_status_or_extra_options=nil, &block)
end
end
- private
- def matching_message_expectation_exists(options)
- expect_render_mock_proxy.send(:__mock_proxy).send(:find_matching_expectation, :render, options)
- end
-
- def matching_stub_exists(options)
- expect_render_mock_proxy.send(:__mock_proxy).send(:find_matching_method_stub, :render, options)
- end
-
- public
- if self.respond_to?(:should_receive) && self.respond_to?(:stub!)
- self.send :alias_method, :orig_should_receive, :should_receive
- self.send :alias_method, :orig_stub!, :stub!
- def raise_with_disable_message(old_method, new_method)
- raise %Q|
- controller.#{old_method}(:render) has been disabled because it
- can often produce unexpected results. Instead, you should
- use the following (before the action):
+ def raise_with_disable_message(old_method, new_method)
+ raise %Q|
+ controller.#{old_method}(:render) has been disabled because it
+ can often produce unexpected results. Instead, you should
+ use the following (before the action):
- controller.#{new_method}(*args)
+ controller.#{new_method}(*args)
- See the rdoc for #{new_method} for more information.
- |
- end
- def should_receive(*args)
- if args[0] == :render
- raise_with_disable_message("should_receive", "expect_render")
- else
- orig_should_receive(*args)
- end
+ See the rdoc for #{new_method} for more information.
+ |
+ end
+ def should_receive(*args)
+ if args[0] == :render
+ raise_with_disable_message("should_receive", "expect_render")
+ else
+ super
end
- def stub!(*args)
- if args[0] == :render
- raise_with_disable_message("stub!", "stub_render")
- else
- orig_stub!(*args)
- end
+ end
+ def stub!(*args)
+ if args[0] == :render
+ raise_with_disable_message("stub!", "stub_render")
+ else
+ super
end
end
@@ -267,6 +253,15 @@ def integrate_views!
def integrate_views?
@integrate_views
end
+
+ def matching_message_expectation_exists(options)
+ expect_render_mock_proxy.send(:__mock_proxy).send(:find_matching_expectation, :render, options)
+ end
+
+ def matching_stub_exists(options)
+ expect_render_mock_proxy.send(:__mock_proxy).send(:find_matching_method_stub, :render, options)
+ end
+
end
Spec::Example::ExampleGroupFactory.register(:controller, self)
@@ -1,6 +1,8 @@
require 'spec/interop/test'
-ActionView::Base.cache_template_extensions = false
+if ActionView::Base.respond_to?(:cache_template_extension)
+ ActionView::Base.cache_template_extensions = false
+end
module Spec
module Rails
@@ -1,4 +1,4 @@
-require 'spec/mocks'
+require 'spec/mocks/framework'
module Spec
module Rails
@@ -1,5 +1,5 @@
require 'spec/example/configuration'
-
+begin
module Spec
module Example
class Configuration
@@ -64,3 +64,8 @@ def global_fixtures=(fixtures)
end
end
end
+rescue Exception => e
+ puts e.message
+ puts e.backtrace
+ raise e
+end
@@ -1,7 +1,7 @@
module Spec
module Rails
module VERSION #:nodoc:
- BUILD_TIME_UTC = 20080504004334
+ BUILD_TIME_UTC = 20080601222934
end
end
end
@@ -120,6 +120,7 @@
end
it "should complain when calling stub!(:render) on the controller" do
+ controller.extend Spec::Mocks::Methods
lambda {
controller.stub!(:render)
}.should raise_error(RuntimeError, /stub!\(:render\) has been disabled/)
@@ -781,3 +781,26 @@ def clear_response
end
end
+describe 'selecting in HTML that contains a mock with null_object' do
+ module HTML
+ class Document
+ def initialize_with_strict_error_checking(text, strict=false, xml=false)
+ initialize_without_strict_error_checking(text, true, xml)
+ end
+ alias_method :initialize_without_strict_error_checking, :initialize
+ alias_method :initialize, :initialize_with_strict_error_checking
+ end
+ end
+
+ describe 'modified HTML::Document' do
+ it 'should raise error on valid HTML even though false is specified' do
+ lambda {HTML::Document.new("<b>#<Spec::Mocks::Mock:0x267b4f0></b>", false, false)}.should raise_error
+ end
+ end
+
+ it 'should not print errors from assert_select' do
+ mock = mock("Dog", :null_object => true)
+ html = "<b>#{mock.colour}</b>"
+ lambda {html.should have_tag('b')}.should_not raise_error
+ end
+end
@@ -40,7 +40,8 @@
it "should raise when hitting the db" do
lambda do
- stub_model(MockableModel).save
+ model = stub_model(MockableModel, :changed => true, :attributes_with_quotes => {'this' => 'that'})
+ model.save
end.should raise_error(Spec::Rails::IllegalDataAccessException, /stubbed models are not allowed to access the database/)
end
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "A sample spec", :type => :model do
+ fixtures :animals
+ it "should pass" do
+ animals(:pig).name.should == "Piggy"
+ end
+end
@@ -1,7 +1,8 @@
require File.dirname(__FILE__) + '/../spec_helper'
-describe "A sample spec" do
+describe "A sample spec", :type => :model do
+ fixtures :animals
it "should pass" do
- true.should === true
+ animals(:pig).name.should == "Pig"
end
end
Oops, something went wrong.

0 comments on commit e3748ac

Please sign in to comment.