Permalink
Browse files

Added ActionController matchers in the RSpec includes

  • Loading branch information...
1 parent a97a2da commit 87fc583d1e8b8e94480994588dfb23843534c8da @jferris jferris committed Mar 3, 2009
Showing with 21 additions and 6 deletions.
  1. +2 −0 lib/shoulda/rspec.rb
  2. +19 −6 test/rspec_test.rb
View
2 lib/shoulda/rspec.rb
@@ -1,9 +1,11 @@
require 'shoulda/active_record/matchers'
+require 'shoulda/action_controller/matchers'
require 'active_support/test_case'
# :enddoc:
module ActiveSupport
class TestCase
include Shoulda::ActiveRecord::Matchers
+ include Shoulda::ActionController::Matchers
end
end
View
25 test/rspec_test.rb
@@ -138,6 +138,7 @@ def configure_spec_rails
def assert_configured
create_model
migrate
+ create_controller
assert_spec_passes
end
@@ -146,24 +147,36 @@ def create_model
insert "validates_presence_of :name",
"app/models/person.rb",
/class Person/
- insert shoulda_example,
+ insert "it { should validate_presence_of(:name) }",
"spec/models/person_spec.rb",
/describe Person do/
end
- def shoulda_example
- return <<-EOS
- it { should validate_presence_of(:name) }
+ def create_controller
+ project_command "script/generate rspec_controller people"
+ insert "def index; render :text => 'Hello'; end",
+ "app/controllers/people_controller.rb",
+ /class PeopleController/
+ shoulda_controller_example = <<-EOS
+ describe PeopleController, "on GET index" do
+ integrate_views
+ subject { controller }
+ before(:each) { get :index }
+ it { should respond_with(:success) }
+ end
EOS
+ insert shoulda_controller_example,
+ "spec/controllers/people_controller_spec.rb"
end
def migrate
project_command "rake db:migrate"
end
def assert_spec_passes
- assert_match /should require name to be set/,
- project_command("rake spec SPEC_OPTS=-fs")
+ result = project_command("rake spec SPEC_OPTS=-fs")
+ assert_match /should require name to be set/, result
+ assert_match /should respond with 200/, result
end
def shoulda_root

0 comments on commit 87fc583

Please sign in to comment.