Skip to content

Commit 10c66e2

Browse files
committed
Add controller attr_reader to controller specs
Closes #39
1 parent 8868bb8 commit 10c66e2

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

cucumber.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default: --require features
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Feature: controller spec readers
2+
3+
Controller specs expose a number of different
4+
attribute readers.
5+
6+
Scenario: access controller
7+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
8+
"""
9+
require "spec_helper.rb"
10+
11+
describe WidgetsController do
12+
it "is available before an action" do
13+
controller.should be_an_instance_of(WidgetsController)
14+
end
15+
end
16+
"""
17+
When I run "rspec ./spec"
18+
Then I should see "1 example, 0 failures"

lib/rspec/rails/example/controller_example_group.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
module ControllerExampleGroupBehaviour
55
extend ActiveSupport::Concern
66

7-
module ControllerClassReader
7+
module ClassAttributeReaders
88
def controller_class
99
describes
1010
end
1111
end
1212

13+
module AttributeReaders
14+
attr_reader :controller
15+
end
16+
1317
included do
1418
extend Rspec::Rails::SetupAndTeardownAdapter
1519
include Rspec::Rails::TestUnitAssertionAdapter
1620
include ActionController::TestCase::Behavior
17-
extend ControllerClassReader
21+
extend ClassAttributeReaders
22+
include AttributeReaders
1823
include Webrat::Matchers
1924
include Webrat::Methods
2025
include Rspec::Matchers

0 commit comments

Comments
 (0)