forked from jonleighton/focused_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaa2502
commit 1c6a414
Showing
7 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'action_controller' | ||
require 'action_view' | ||
require 'action_dispatch' | ||
require 'rspec/rails' | ||
require 'focused_controller/functional_test_helper' | ||
|
||
module FocusedController | ||
module RSpecFunctionalHelper | ||
def self.append_features(base) | ||
base.class_eval do | ||
# This must be included first | ||
include RSpec::Rails::ControllerExampleGroup | ||
extend ClassMethods | ||
include FocusedController::FunctionalTestHelper | ||
end | ||
|
||
super | ||
end | ||
|
||
module ClassMethods | ||
def controller_class | ||
controller = metadata[:example_group][:description_args].first | ||
|
||
if controller.respond_to?(:new) | ||
controller | ||
else | ||
super | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require 'spec_helper' | ||
|
||
describe PostsController do | ||
include FocusedController::RSpecFunctionalHelper | ||
|
||
before do | ||
@post = Post.create(:title => 'Hello', :body => 'Omg') | ||
end | ||
|
||
describe PostsController::Index do | ||
it "should get index" do | ||
get | ||
response.should be_success | ||
subject.posts.should_not be_nil | ||
end | ||
end | ||
|
||
describe PostsController::New do | ||
it "should get new" do | ||
get | ||
response.should be_success | ||
end | ||
end | ||
|
||
describe PostsController::Create do | ||
it "should create post" do | ||
expect { post post: @post.attributes }.to change(Post, :count).by(1) | ||
response.should redirect_to(post_path(subject.post)) | ||
end | ||
end | ||
|
||
describe PostsController::Show do | ||
it "should show post" do | ||
get id: @post | ||
response.should be_success | ||
end | ||
end | ||
|
||
describe PostsController::Edit do | ||
it "should get edit" do | ||
get id: @post | ||
response.should be_success | ||
end | ||
end | ||
|
||
describe PostsController::Update do | ||
it "should update post" do | ||
put id: @post, post: @post.attributes | ||
response.should redirect_to(post_path(subject.post)) | ||
end | ||
end | ||
|
||
describe PostsController::Destroy do | ||
it "should destroy post" do | ||
expect { delete id: @post }.to change(Post, :count).by(-1) | ||
response.should redirect_to(posts_path) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'helper' | ||
require 'focused_controller/rspec_functional_helper' | ||
|
||
module FocusedController | ||
module RSpecFunctionalHelper | ||
class FakePostsController | ||
class Action < ActionController::Base; end | ||
class Index < Action; end | ||
class Show < Action; end | ||
end | ||
|
||
index_spec = RSpec::Core::ExampleGroup.describe FakePostsController::Index do | ||
include RSpec::Rails::ControllerExampleGroup | ||
include FocusedController::RSpecFunctionalHelper | ||
end | ||
|
||
show_spec = nil | ||
RSpec::Core::ExampleGroup.describe FakePostsController do | ||
include RSpec::Rails::ControllerExampleGroup | ||
include FocusedController::RSpecFunctionalHelper | ||
|
||
show_spec = describe(FakePostsController::Show) {} | ||
end | ||
|
||
describe RSpecFunctionalHelper do | ||
subject { index_spec.new } | ||
|
||
it 'automatically determines the controller class' do | ||
index_spec.controller_class.must_equal FakePostsController::Index | ||
show_spec.controller_class.must_equal FakePostsController::Show | ||
end | ||
|
||
it 'includes the FocusedController::FunctionalTestHelper' do | ||
subject.is_a?(FocusedController::FunctionalTestHelper).must_equal true | ||
end | ||
end | ||
end | ||
end |