# \[Rails\] Can't get controller test working with RSpec 2 and edge Rails 3

**URL:** <https://www.ruby-forum.com/t/rails-cant-get-controller-test-working-with-rspec-2-and-edge-rails-3/190733>\
**Category:** RSpec\
**Created:** [June 26, 2010, 12:18am UTC](https://www.ruby-forum.com/t/rails-cant-get-controller-test-working-with-rspec-2-and-edge-rails-3/190733 "2010-06-26T00:18:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 26, 2010, 12:18am UTC](https://www.ruby-forum.com/t/rails-cant-get-controller-test-working-with-rspec-2-and-edge-rails-3/190733/1 "2010-06-26T00:18:35Z")

</div>

Not sure if this is a Rails 3 issue or an RSpec 2 issue, but I can’t  
seem to  
get a standard controller test working - it seems that the ‘get’ method  
can’t be found.

I have a controller test that looks like this (named  
“discrepancies\_controller\_spec.rb” in spec/controllers directory):

require ‘spec\_helper’

describe DiscrepanciesController do  
before :each do  
Discrepancy.delete\_all  
end

it “resolves a discrepancy” do  
discrepancy = Discrepancy.create(:my\_number=\>“12345”, :status=\>“Open”)

get :resolve, :id =\> discrepancy.id  
retrieved\_discrepancy = Discrepancy.find\_by\_my\_number(“12345”)  
retrieved\_discrepancy.status.should == “Resolved”  
end  
end

(Yes, I’m aware of the security implications of modifying data with an  
HTTP/GET - that’s a separate issue…)  
When I run it with rake, I get the following error:

1. DiscrepanciesController resolves a discrepancy  
Failure/Error: Unable to find C to read failed line  
undefined method `get’ for  
#\<RSpec::Core::ExampleGroup::Nested\_1:0xc9170d0 @\_\_memoized={}\>
# ./spec/controllers/discrepancies\_controller\_spec.rb:38\* (ignore

the  
line number, commented out code was removed from the sample)\*  
#  
C:/Users/Patrick\_Gannon/.bundle/ruby/1.8/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active\_support/dependencies.rb:212:in  
`inject' # C:/Ruby187/bin/rake:19:in`load’  
# C:/Ruby187/bin/rake:19

I can manage to test the controller action by instantiating the  
controller  
myself and calling the controller action directly, and it works, but its  
ugly because I have to mock out things like ‘respond\_to’ and ‘params’.

Other pertinent information: I am running Windows 7 32-bit, Ruby 1.8.7  
(2010-01-10 patchlevel 249) [i386-wingw32], edge Rails 3 and  
MongoDB/MongoMapper. Here is my list of installed gems (via ‘bundle  
gem’ -  
all my installed gems were installed by Bundler)

- abstract (1.0.0)
- actionmailer (3.0.0.beta4)
- actionpack (3.0.0.beta4)
- activemodel (3.0.0.beta4)
- activerecord (3.0.0.beta4)
- activeresource (3.0.0.beta4)
- activesupport (3.0.0.beta4)
- arel (0.4.0)
- bcrypt-ruby (2.1.2)
- bson (1.0.3)
- bson\_ext (1.0.1)
- builder (2.1.2)
- bundler (0.9.26)
- capistrano (2.5.19)
- capybara (0.3.8 a94f99)
- cucumber (0.8.3)
- cucumber-rails (0.3.2 master-b75110)
- culerity (0.2.10)
- database\_cleaner (0.5.2 7ea99d)
- devise (1.1.rc1 88ab2f)
- diff-lcs (1.1.2)
- erubis (2.6.5)
- factory\_girl (1.3.0)
- factory\_girl\_rails (1.0)
- faker (0.3.1)
- ffi (0.6.3)
- gherkin (2.0.2)
- highline (1.5.2)
- i18n (0.4.1)
- jnunemaker-validatable (1.8.4)
- joint (0.3.2 11a094)
- json\_pure (1.4.3)
- mail (2.2.5)
- mime-types (1.16)
- mongo (1.0.3)
- mongo\_mapper (0.8.2)
- net-scp (1.0.2)
- net-sftp (2.0.4)
- net-ssh (2.0.23)
- net-ssh-gateway (1.0.1)
- nokogiri (1.4.2.1)
- plucky (0.3.2)
- polyglot (0.3.1)
- rack (1.1.0)
- rack-mount (0.6.6)
- rack-test (0.5.4)
- rails (3.0.0.beta4 6682cc)
- railties (3.0.0.beta4)
- rake (0.8.7)
- rspec (2.0.0.beta.13)
- rspec-core (2.0.0.beta.13)
- rspec-expectations (2.0.0.beta.13)
- rspec-mocks (2.0.0.beta.13)
- rspec-rails (2.0.0.beta.13)
- selenium-webdriver (0.0.24)
- term-ansicolor (1.0.5)
- thor (0.13.6)
- treetop (1.4.8)
- trollop (1.16.2)
- tzinfo (0.3.22)
- wand (0.2.1)
- warden (0.10.7)
- webrat (0.7.1)

I also added a puts statement in the test to show what methods are  
available  
in the test fixture, and “get” is not in the list. Here is what is in  
the  
list:

“\_\_memoized”, “ **should\_for\_example\_group** ”,  
“ **should\_not\_for\_example\_group** ”, “\_fixture\_class\_names”,  
“\_fixture\_path”,  
“\_fixture\_table\_names”, “\_pre\_loaded\_fixtures”, “\_setup\_mocks”,  
“\_teardown\_mocks”, “\_use\_instantiated\_fixtures”,  
“\_use\_transactional\_fixtures”, “\_verify\_mocks”, “a\_kind\_of”,  
“allow\_message\_expectations\_on\_nil”, “an\_instance\_of”, “any\_args”,  
“anything”, “assert”, “assert\_block”, “assert\_equal”, “assert\_in\_delta”,  
“assert\_instance\_of”, “assert\_kind\_of”, “assert\_match”, “assert\_nil”,  
“assert\_no\_match”, “assert\_not\_equal”, “assert\_not\_nil”,  
“assert\_not\_same”, “assert\_nothing\_raised”, “assert\_nothing\_thrown”,  
“assert\_operator”, “assert\_raise”, “assert\_raises”, “assert\_respond\_to”,  
“assert\_same”, “assert\_send”, “assert\_throws”, “be”, “be\_a”,  
“be\_a\_kind\_of”,  
“be\_a\_new”, “be\_an”, “be\_an\_instance\_of”, “be\_close”, “be\_false”,  
“be\_instance\_of”, “be\_kind\_of”, “be\_nil”, “be\_true”, “boolean”,  
“build\_message”, “change”, “described\_class”, “double”, “duck\_type”,  
“eq”,  
“eql”, “equal”, “example”, “example=”, “exist”, “expect”,  
“fixture\_class\_names”, “fixture\_class\_names?”, “fixture\_path”,  
“fixture\_path?”, “fixture\_table\_names”,  
“fixture\_table\_names?”, “flunk”, “hash\_including”, “hash\_not\_including”,  
“have”, “have\_at\_least”, “have\_at\_most”, “have\_exactly”, “include”,  
“instance\_of”, “kind\_of”, “match”, “method\_missing”, “method\_name”,  
“mock”,  
“mock\_discrepancy”, “mock\_model”, “no\_args”, “pending”,  
“pre\_loaded\_fixtures”, “pre\_loaded\_fixtures?”, “raise\_error”,  
“respond\_to”,  
“run\_in\_transaction?”, “running\_example”, “satisfy”, “setup\_fixtures”,  
“stub\_model”, “subject”, “teardown\_fixtures”, “throw\_symbol”,  
“use\_instantiated\_fixtures”, “use\_instantiated\_fixtures?”,  
“use\_transactional\_fixtures”, “use\_transactional\_fixtures?”

Thanks in advance for any help you can provide - sorry for the long  
email  
(didn’t want to exclude anything…)

Pat

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 26, 2010, 4:30am UTC](https://www.ruby-forum.com/t/rails-cant-get-controller-test-working-with-rspec-2-and-edge-rails-3/190733/2 "2010-06-26T04:30:19Z")

</div>

On Jun 25, 2010, at 5:02 PM, Patrick G. wrote:

> (Yes, I’m aware of the security implications of modifying data with an HTTP/GET - that’s a separate issue…)  
> When I run it with rake, I get the following error:
> 
> 1. DiscrepanciesController resolves a discrepancy  
> Failure/Error: Unable to find C to read failed line  
> undefined method `get’ for #\<RSpec::Core::ExampleGroup::Nested\_1:0xc9170d0 @\_\_memoized={}\>
> # ./spec/controllers/discrepancies\_controller\_spec.rb:38 (ignore the line number, commented out code was removed from the sample)
> 
> # C:/Users/Patrick\_Gannon/.bundle/ruby/1.8/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/activesupport/lib/active\_support/dependencies.rb:212:in `inject’
> 
> # C:/Ruby187/bin/rake:19:in `load’
> 
> # C:/Ruby187/bin/rake:19

I’m surprised this is the first time this has come up with rspec-2, but  
here we are 🙂

This is a path-separator bug that I’ll resolve in the next release. For  
now, you can do this in your controller specs:

describe DiscrepanciesController do  
include RSpec::Rails::ControllerExampleGroup

That should work fine.

If you want to do a more global workaround, add this to your spec\_helper  
config:

RSpec.configure do |c|  
c.include RSpec::Rails::ControllerExampleGroup, :example\_group =\> {  
:file\_path =\> /\bspec[\/]controllers[\/]/ }  
end

HTH,  
David

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [June 26, 2010, 7:46am UTC](https://www.ruby-forum.com/t/rails-cant-get-controller-test-working-with-rspec-2-and-edge-rails-3/190733/3 "2010-06-26T07:46:23Z")

</div>

On Jun 25, 9:21 pm, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > require ‘spec\_helper’
> 
> > ```
> > undefined method `get' for #<RSpec::Core::ExampleGroup::Nested_1:0xc9170d0 @__memoized={}>
> > 
> > ```
> 
> include RSpec::Rails::ControllerExampleGroup  
> David  
> FYI: [Rails-specific example group extensions not loading up in Windows · Issue #99 · rspec/rspec-rails · GitHub](http://github.com/rspec/rspec-rails/issues/99)

---

<div class="post-metadata">

**Author:** ![pgundlach](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b9e5f3/32.png) [@pgundlach](https://www.ruby-forum.com/u/pgundlach)\
**Post date:** [March 7, 2011, 10:55am UTC](https://www.ruby-forum.com/t/rails-cant-get-controller-test-working-with-rspec-2-and-edge-rails-3/190733/4 "2011-03-07T10:55:36Z")

</div>

[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote in post #921577:

> On Jun 25, 9:21 pm, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > > require ‘spec\_helper’
> > 
> > > ```
> > > undefined method `get' for
> > > 
> > > ```

#\<RSpec::Core::ExampleGroup::Nested\_1:0xc9170d0

> @\_\_memoized={}\>
> 
> > include RSpec::Rails::ControllerExampleGroup  
> > David  
> > FYI: [Rails-specific example group extensions not loading up in Windows · Issue #99 · rspec/rspec-rails · GitHub](http://github.com/rspec/rspec-rails/issues/99)

Just add config.include RSpec::Rails::ControllerExampleGroup in  
spec\_helper.rb
