# RSpec

**URL:** https://www.ruby-forum.com/c/testing/rspec/25.md?page=22

[Latest](https://www.ruby-forum.com/latest.md) · [Categories](https://www.ruby-forum.com/categories.md) · [Tags](https://www.ruby-forum.com/tags.md)

**Page:** 23

---

## [RSpec interacting with Test::Unit: weird "is already defined" error](https://www.ruby-forum.com/t/rspec-interacting-with-test-weird-is-already-defined-error/199869)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 5\
**Last updated:** [November 30, 2010, 10:01pm UTC](https://www.ruby-forum.com/t/rspec-interacting-with-test-weird-is-already-defined-error/199869 "2010-11-30T22:01:37Z")

</div>

Hey everyone, (I’m a newbie, so if I’m doing something wrong, please let me know! ^^) I’m getting weird errors when I mix RSpec and Test::Unit tests. Here is how to reproduce it with Rails 3: Run “rails new railsapp…

---

## [Rspec2, rails 3, subdomain constraints](https://www.ruby-forum.com/t/rspec2-rails-3-subdomain-constraints/199639)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 2\
**Last updated:** [November 30, 2010, 12:34am UTC](https://www.ruby-forum.com/t/rspec2-rails-3-subdomain-constraints/199639 "2010-11-30T00:34:38Z")

</div>

I’m trying to constrain access to admin routes in my application to either www or canonical. I need the custom constraint in root\_domain.rb (RootDomain) to handle the canonical part. Since the subdomains will represen…

---

## [\[TDD\] \[Rails\] - Rspec test for application\_helper.rb fails when trying to access application\_control](https://www.ruby-forum.com/t/tdd-rails-rspec-test-for-application-helper-rb-fails-when-trying-to-access-application-control/199835)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 0\
**Last updated:** [November 30, 2010, 12:07am UTC](https://www.ruby-forum.com/t/tdd-rails-rspec-test-for-application-helper-rb-fails-when-trying-to-access-application-control/199835 "2010-11-30T00:07:03Z")

</div>

In a method named logo in my application helper, I reference an application controller method (current\_account) that has been marked as a helper method with the following syntax: helper\_method :current\_account When I…

---

## [Rspec-core-2.2.1 is released!](https://www.ruby-forum.com/t/rspec-core-2-2-1-is-released/199818)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 0\
**Last updated:** [November 29, 2010, 8:21pm UTC](https://www.ruby-forum.com/t/rspec-core-2-2-1-is-released/199818 "2010-11-29T20:21:35Z")

</div>

rspec-core-2.2.1 / 2010-11-28 full changelog Bug fixes alias\_method instead of override Kernel#method\_missing (John W.) changed --autotest to --tty in generated command (MIKAMI Yoshiyuki) revert change to debugger (…

---

## [How To Mock A Chain (specifically ActionMailerModel.method.deliver)](https://www.ruby-forum.com/t/how-to-mock-a-chain-specifically-actionmailermodel-method-deliver/199631)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 2\
**Last updated:** [November 29, 2010, 6:36pm UTC](https://www.ruby-forum.com/t/how-to-mock-a-chain-specifically-actionmailermodel-method-deliver/199631 "2010-11-29T18:36:44Z")

</div>

Hi, In Rails 3 you deliver a mail message with the ActionMailerModel.method.deliver syntax (e.g. Notifier.welcome\_message.deliver). How do you test that this method is called in Rspec. I’m looking for an equivalent t…

---

## [No such file to load - spec/test/unit](https://www.ruby-forum.com/t/no-such-file-to-load-spec-test-unit/199650)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 2\
**Last updated:** [November 29, 2010, 4:14pm UTC](https://www.ruby-forum.com/t/no-such-file-to-load-spec-test-unit/199650 "2010-11-29T16:14:27Z")

</div>

Under the older version of rspec, I’m able to run my script successfully by running “spec randomperform.rb” I’ve now installed the newest rspec, and it does not work for me. If I run the command: rspec randomperform…

---

## [Stub\_chain together with should\_receive](https://www.ruby-forum.com/t/stub-chain-together-with-should-receive/199647)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 4\
**Last updated:** [November 28, 2010, 9:04pm UTC](https://www.ruby-forum.com/t/stub-chain-together-with-should-receive/199647 "2010-11-28T21:04:39Z")

</div>

Hello. I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method offset. Unfortunately the code be…

---

## [For web apps, when to use webrat, when to spec controllers?](https://www.ruby-forum.com/t/for-web-apps-when-to-use-webrat-when-to-spec-controllers/199743)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 0\
**Last updated:** [November 28, 2010, 4:46am UTC](https://www.ruby-forum.com/t/for-web-apps-when-to-use-webrat-when-to-spec-controllers/199743 "2010-11-28T04:46:47Z")

</div>

Hi, I’m trying to better understand when to use the integration testing approach a la, say, Webrat, and when to rely on spec’ing my (Rails) controllers (MVC pattern). Let me give the current example that has brought …

---

## [Lastest versions for 2.3.10?](https://www.ruby-forum.com/t/lastest-versions-for-2-3-10/199638)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 1\
**Last updated:** [November 25, 2010, 8:42pm UTC](https://www.ruby-forum.com/t/lastest-versions-for-2-3-10/199638 "2010-11-25T20:42:29Z")

</div>

Can someone tell me what the latest versions for rspec / cucumber for a rails 2.3.10 project? Currently I get this error $: script/generate rspec Couldn’t find ‘rspec’ generator My enviroment.rb : config.gem ‘rspec…

---

## [Be\_valid method undefined on model spec](https://www.ruby-forum.com/t/be-valid-method-undefined-on-model-spec/199632)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 3\
**Last updated:** [November 25, 2010, 8:21pm UTC](https://www.ruby-forum.com/t/be-valid-method-undefined-on-model-spec/199632 "2010-11-25T20:21:09Z")

</div>

Hi all, I’m using rspec-rails and have a simple model spec which fails with the following trace: undefined local variable or method \`be\_valid’ for #\<Class: 0x00000102c6e820\> (NameError) Full trace: gist:713164 · Git…

---

## [How do I generate specs for existing controllers?](https://www.ruby-forum.com/t/how-do-i-generate-specs-for-existing-controllers/199636)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 4\
**Last updated:** [November 25, 2010, 7:02pm UTC](https://www.ruby-forum.com/t/how-do-i-generate-specs-for-existing-controllers/199636 "2010-11-25T19:02:43Z")

</div>

I want to generate boilerplate code for existing controller, models and views. Is there a command or a gem that lets me do that?

---

## [Rspec: rendering a certain template with a certain layout is needed](https://www.ruby-forum.com/t/rspec-rendering-a-certain-template-with-a-certain-layout-is-needed/199634)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 1\
**Last updated:** [November 25, 2010, 2:34pm UTC](https://www.ruby-forum.com/t/rspec-rendering-a-certain-template-with-a-certain-layout-is-needed/199634 "2010-11-25T14:34:27Z")

</div>

Hello! I was trying render my view with a custom layout: render :template =\> “cards/show.html.erb”, :layout =\> ‘application’ And caught an error: Failure/Error: render :text =\> ‘Text’, :layout =\> ‘application’ Missi…

---

## [Spec::Mocks::MockExpectationError](https://www.ruby-forum.com/t/spec-mockexpectationerror/199566)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 3\
**Last updated:** [November 25, 2010, 2:01pm UTC](https://www.ruby-forum.com/t/spec-mockexpectationerror/199566 "2010-11-25T14:01:46Z")

</div>

hii I am initial level of rspec.I am getting a error nil class. My Controller code is as follows class UsersController \< ApplicationController before\_filter :have\_hard\_drive? # filter check for authorized user to ac…

---

## [Puzzled about the rspec tests generated by Rails3](https://www.ruby-forum.com/t/puzzled-about-the-rspec-tests-generated-by-rails3/199607)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 2\
**Last updated:** [November 25, 2010, 10:14am UTC](https://www.ruby-forum.com/t/puzzled-about-the-rspec-tests-generated-by-rails3/199607 "2010-11-25T10:14:58Z")

</div>

Hi all I am puzzled about the rspec tests that are generated by Rails3 scaffolding. I am however not sure if this is the correct place to discuss this issue. It might be that a rails ML/chat is better suited for that…

---

## [Specs for controllers and rescue\_from](https://www.ruby-forum.com/t/specs-for-controllers-and-rescue-from/199434)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 3\
**Last updated:** [November 25, 2010, 5:12am UTC](https://www.ruby-forum.com/t/specs-for-controllers-and-rescue-from/199434 "2010-11-25T05:12:27Z")

</div>

Hey guys. My ApplicationController rescues Mongoid::Errors::DocumentNotFound errors like this: class ApplicationController \< ActionController::Base rescue\_from Mongoid::Errors::DocumentNotFound, :with =\> :resource\_no…

---

## [NestedIterator Assistance](https://www.ruby-forum.com/t/nestediterator-assistance/199580)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 1\
**Last updated:** [November 24, 2010, 3:53pm UTC](https://www.ruby-forum.com/t/nestediterator-assistance/199580 "2010-11-24T15:53:28Z")

</div>

Hello everyone, Metric\_fu is informing me of some nested iterators, and I was hoping to gather some advice on how to refactor this method to make it more correct. Hopefully this will assist me in refactoring many othe…

---

## [Stub\_chain together with should\_receive](https://www.ruby-forum.com/t/stub-chain-together-with-should-receive/199557)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 1\
**Last updated:** [November 24, 2010, 3:22pm UTC](https://www.ruby-forum.com/t/stub-chain-together-with-should-receive/199557 "2010-11-24T15:22:24Z")

</div>

Hello. I am trying to test if in a method calling chain one of the methods get a specific parameter. In the below code for example MyModel must receive the parameter 0 for the method “offset”. Unfortunately the code …

---

## [Newbie questions - Best practice for loading local db data and model tests? (factory\_girl , debuggin](https://www.ruby-forum.com/t/newbie-questions-best-practice-for-loading-local-db-data-and-model-tests-factory-girl-debuggin/199547)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 1\
**Last updated:** [November 24, 2010, 1:24am UTC](https://www.ruby-forum.com/t/newbie-questions-best-practice-for-loading-local-db-data-and-model-tests-factory-girl-debuggin/199547 "2010-11-24T01:24:21Z")

</div>

I’m pretty much a newbie with Rails and RSpec. I’m trying to follow best practices as I start to work on my own Rails side project. I’m using: rspec 2.1.0 / Rails 3.0.1 / ruby 1.9.2 Currently I have a Rake task that…

---

## [How to mock a logged in user](https://www.ruby-forum.com/t/how-to-mock-a-logged-in-user/199472)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 4\
**Last updated:** [November 23, 2010, 4:37pm UTC](https://www.ruby-forum.com/t/how-to-mock-a-logged-in-user/199472 "2010-11-23T16:37:58Z")

</div>

I need to update something for a logged in user. My controller code for the action is: def som\_action @\_current\_user.save\_choice(params) end My application\_controller.rb contains the following: class ApplicationCon…

---

## [Testing update, flash\[:error\]](https://www.ruby-forum.com/t/testing-update-flash-error/199474)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 4\
**Last updated:** [November 23, 2010, 1:07am UTC](https://www.ruby-forum.com/t/testing-update-flash-error/199474 "2010-11-23T01:07:27Z")

</div>

Hello everyone, I’m trying to write a failure test for updating a model, but the flash\[:error\] seems to be causing a problem. All code can be found here: http://pastie.org/private/zcu0fpzbfbjbleocmf1bqw I’ve also tr…

---

## [Specs pass individually, but fail using autotest](https://www.ruby-forum.com/t/specs-pass-individually-but-fail-using-autotest/199433)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 4\
**Last updated:** [November 22, 2010, 7:00am UTC](https://www.ruby-forum.com/t/specs-pass-individually-but-fail-using-autotest/199433 "2010-11-22T07:00:24Z")

</div>

Hi, I’m trying to run autotest and I’m using ryanb’s nifty authentication with Rails 3 and Rpec 2. When I run autotest, the user model spec fails all its validation tests with the “error\_on” matcher. If I run the spe…

---

## [Testing user\_controller update action](https://www.ruby-forum.com/t/testing-user-controller-update-action/199324)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 2\
**Last updated:** [November 18, 2010, 8:20pm UTC](https://www.ruby-forum.com/t/testing-user-controller-update-action/199324 "2010-11-18T20:20:59Z")

</div>

Hello everyone, I’m trying to test the update action in my user controller, but unfortunately having troubles. You can find all of my code and relevant code here: http://pastie.org/private/odzbqvcoe8kdnh97ocaxia You …

---

## [Testing Controller 'show' action](https://www.ruby-forum.com/t/testing-controller-show-action/199279)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 3\
**Last updated:** [November 18, 2010, 4:54pm UTC](https://www.ruby-forum.com/t/testing-controller-show-action/199279 "2010-11-18T16:54:05Z")

</div>

Hello, I’m still pretty new to Rails, and I’ve used rspec on all of my models with success. Now I’m working on the controllers, but I’m having difficulty. Everything I try is giving me a response of false, and I was h…

---

## [How to use request helpers outside of controller specs?](https://www.ruby-forum.com/t/how-to-use-request-helpers-outside-of-controller-specs/199256)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 3\
**Last updated:** [November 17, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/how-to-use-request-helpers-outside-of-controller-specs/199256 "2010-11-17T21:07:30Z")

</div>

I asked this questions on some other places before, but have found no solution yet. I’d like to include the request helper (from ActionDispatch::Integration::RequestHelpers, like post and xhr methods) also in some spe…

---

## [Rspec not loading .rspec file](https://www.ruby-forum.com/t/rspec-not-loading-rspec-file/199272)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 0\
**Last updated:** [November 17, 2010, 6:39pm UTC](https://www.ruby-forum.com/t/rspec-not-loading-rspec-file/199272 "2010-11-17T18:39:16Z")

</div>

Hey, For some reason i can’t seem to make rake spec or bin/rspec load the contents of the current working directory’s .rspec, nor my ~/.rspec. Is there some kind of incantation required to make this work? Thanks, Ja…

---

## [Shared contexts](https://www.ruby-forum.com/t/shared-contexts/199208)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 1\
**Last updated:** [November 17, 2010, 3:47pm UTC](https://www.ruby-forum.com/t/shared-contexts/199208 "2010-11-17T15:47:10Z")

</div>

Suppose we have this class: class MarbleMachine def insert color # process marble of color ‘color’ end def press button # process a push of the given button end def output # compute a result end end Let’s pre…

---

## [View.should render\_template best practices?](https://www.ruby-forum.com/t/view-should-render-template-best-practices/199240)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 4\
**Last updated:** [November 17, 2010, 3:30pm UTC](https://www.ruby-forum.com/t/view-should-render-template-best-practices/199240 "2010-11-17T15:30:10Z")

</div>

I’ve been looking for the definitive answer for months now, and the RSpec book doesn’t touch on it at all: How do we now handle stubbing out rendering of partials in view specs in RSpec2? I have a large (35K+ lines o…

---

## [Rspec troubles](https://www.ruby-forum.com/t/rspec-troubles/199239)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 0\
**Last updated:** [November 17, 2010, 5:05am UTC](https://www.ruby-forum.com/t/rspec-troubles/199239 "2010-11-17T05:05:54Z")

</div>

I have a repository up here with a basic rails app and 3 classes with one spec file. If you run the spec you will see test failures that I would expect to pass. Anyone want to explain what I am doing wrong?

---

## [Should\_receive(:render).with(some\_option) not working](https://www.ruby-forum.com/t/should-receive-render-with-some-option-not-working/199206)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 0\
**Last updated:** [November 16, 2010, 8:13pm UTC](https://www.ruby-forum.com/t/should-receive-render-with-some-option-not-working/199206 "2010-11-16T20:13:32Z")

</div>

Hello. As some former posts already mentioned there is some difficulty to test the render method when also checking for arguments: http://rails-bestpractices.com/questions/17-test-the-render-method-in-a-controller-wit…

---

## [Why should\_receive behaves differently](https://www.ruby-forum.com/t/why-should-receive-behaves-differently/199172)

<div class="topic-metadata">

**Author:** [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Replies:** 2\
**Last updated:** [November 16, 2010, 9:44am UTC](https://www.ruby-forum.com/t/why-should-receive-behaves-differently/199172 "2010-11-16T09:44:11Z")

</div>

Hi friends in my rspec\_controller 1\]@user.articles.should\_receive(:find\_by\_id).with(‘1’).and\_return(@article) get :show,:id =\> 1 in above example 1 if i mention get :show, :id =\> 1 below the schould\_receive it is w…

[Previous page](https://www.ruby-forum.com/c/testing/rspec/25.md?page=21)

[Next page](https://www.ruby-forum.com/c/testing/rspec/25.md?page=23)
