# RSpec

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

[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:** 28

---

## [Passing a block to a stub method](https://www.ruby-forum.com/t/passing-a-block-to-a-stub-method/194940)

<div class="topic-metadata">

**Author:** [@nicolas](https://www.ruby-forum.com/u/nicolas)\
**Replies:** 2\
**Last updated:** [September 14, 2010, 4:38am UTC](https://www.ruby-forum.com/t/passing-a-block-to-a-stub-method/194940 "2010-09-14T04:38:37Z")

</div>

It seems that rspec doesn’t support passing a block to a stub method. This code fails: def call\_build\_with\_block(o) o.build do puts “hello” end end describe “call\_build\_with\_block” do it “should call build with b…

---

## [Rspec tasks with rspec-rails 2.0](https://www.ruby-forum.com/t/rspec-tasks-with-rspec-rails-2-0/194942)

<div class="topic-metadata">

**Author:** [@kyle](https://www.ruby-forum.com/u/kyle)\
**Replies:** 1\
**Last updated:** [September 14, 2010, 4:27am UTC](https://www.ruby-forum.com/t/rspec-tasks-with-rspec-rails-2-0/194942 "2010-09-14T04:27:29Z")

</div>

After updating to Rails 3 and Rspec-rails 2.0, the tasks defined in rspec.rake do not work anymore. I instead get this, even when running the rake tasks via ‘bundle exec’: You are trying to run an rspec rake task de…

---

## [In rails 3 and rspec 2, how can I test the layout used by a call to render()?](https://www.ruby-forum.com/t/in-rails-3-and-rspec-2-how-can-i-test-the-layout-used-by-a-call-to-render/194939)

<div class="topic-metadata">

**Author:** [@Lowell](https://www.ruby-forum.com/u/Lowell)\
**Replies:** 1\
**Last updated:** [September 14, 2010, 4:26am UTC](https://www.ruby-forum.com/t/in-rails-3-and-rspec-2-how-can-i-test-the-layout-used-by-a-call-to-render/194939 "2010-09-14T04:26:54Z")

</div>

I’m trying to test that a view was rendered with a given layout. How can I test which layout was used for the call to render() ? The call that I want to test looks like this: render :some\_view, :layout =\> ‘some\_layout…

---

## [Incorrect wrong number of arguments exception when stubbing find](https://www.ruby-forum.com/t/incorrect-wrong-number-of-arguments-exception-when-stubbing-find/194937)

<div class="topic-metadata">

**Author:** [@Michael\_Xavier](https://www.ruby-forum.com/u/Michael_Xavier)\
**Replies:** 1\
**Last updated:** [September 14, 2010, 4:26am UTC](https://www.ruby-forum.com/t/incorrect-wrong-number-of-arguments-exception-when-stubbing-find/194937 "2010-09-14T04:26:19Z")

</div>

I’m working with a subclass of ActiveResource and I came across this oddity when trying to stub its find method. Occurring with rspec 1.3.0: The spec code looks like: \[1,2\].each {|id| Hive::CategoryResource.should\_r…

---

## [May expect { ... }.to\_not be changed to expect { ... }.not\_to?](https://www.ruby-forum.com/t/may-expect-to-not-be-changed-to-expect-not-to/194941)

<div class="topic-metadata">

**Author:** [@Takumi\_Tsunokake](https://www.ruby-forum.com/u/Takumi_Tsunokake)\
**Replies:** 1\
**Last updated:** [September 14, 2010, 4:14am UTC](https://www.ruby-forum.com/t/may-expect-to-not-be-changed-to-expect-not-to/194941 "2010-09-14T04:14:37Z")

</div>

Hi, I’m Takumi Tsunokake. I think expect { … }.not\_to rails\_error is more grammatical and natural than expect { … }.to\_not rails\_error Are there any backgrounds and reasons of decision for expect { … }.to\_not, not …

---

## [Rspec-rails setup in Rails 3](https://www.ruby-forum.com/t/rspec-rails-setup-in-rails-3/194938)

<div class="topic-metadata">

**Author:** [@coolmenu](https://www.ruby-forum.com/u/coolmenu)\
**Replies:** 1\
**Last updated:** [September 14, 2010, 4:12am UTC](https://www.ruby-forum.com/t/rspec-rails-setup-in-rails-3/194938 "2010-09-14T04:12:51Z")

</div>

I’m missing something in my setup of rspec-rails in a rails 3 project. I’ve included the link to the gist. It seems that it doesn’t recognize rails routes for some reason…getting “undefined local variable or method”…

---

## [\[BDD\] NoMethodError raised when calling #stub with incorrect parameters](https://www.ruby-forum.com/t/bdd-nomethoderror-raised-when-calling-stub-with-incorrect-parameters/194927)

<div class="topic-metadata">

**Author:** [@nicholas-henry](https://www.ruby-forum.com/u/nicholas-henry)\
**Replies:** 0\
**Last updated:** [September 13, 2010, 11:15pm UTC](https://www.ruby-forum.com/t/bdd-nomethoderror-raised-when-calling-stub-with-incorrect-parameters/194927 "2010-09-13T23:15:29Z")

</div>

I’m new to RSpec and came across an interesting situation where calling a stubbed method with different parameters from those specified, raises a misleading error. Some code to illustrate: (rspec 1.3.0) describe Pers…

---

## [\[Rails\] Unexpected calls to \*\_before\_type\_cast in view specs](https://www.ruby-forum.com/t/rails-unexpected-calls-to-before-type-cast-in-view-specs/194921)

<div class="topic-metadata">

**Author:** [@Jon\_Wood](https://www.ruby-forum.com/u/Jon_Wood)\
**Replies:** 0\
**Last updated:** [September 13, 2010, 7:27pm UTC](https://www.ruby-forum.com/t/rails-unexpected-calls-to-before-type-cast-in-view-specs/194921 "2010-09-13T19:27:45Z")

</div>

Good evening, I’m having some issues with the view specs on a project newly upgraded from rspec-rails-1.2.x to rspec-rails-1.3.2, and also having had a Rails upgrade from 2.3.5 to 2.3.9 done at the same time. My view…

---

## [Rails3: in production i get uninitialised constant rspec?](https://www.ruby-forum.com/t/rails3-in-production-i-get-uninitialised-constant-rspec/194889)

<div class="topic-metadata">

**Author:** [@nathanvda](https://www.ruby-forum.com/u/nathanvda)\
**Replies:** 3\
**Last updated:** [September 13, 2010, 4:53pm UTC](https://www.ruby-forum.com/t/rails3-in-production-i-get-uninitialised-constant-rspec/194889 "2010-09-13T16:53:12Z")

</div>

I am trying to deploy my rails3 application in a production environment. But when i run my first rake task: RAILS\_ENV=production rake db:setup i always get the following result: rake aborted! uninitialized constant R…

---

## [Re-using Rspec Matchers](https://www.ruby-forum.com/t/re-using-rspec-matchers/194671)

<div class="topic-metadata">

**Author:** [@bk669](https://www.ruby-forum.com/u/bk669)\
**Replies:** 4\
**Last updated:** [September 9, 2010, 4:13am UTC](https://www.ruby-forum.com/t/re-using-rspec-matchers/194671 "2010-09-09T04:13:27Z")

</div>

Hey Everyone, Is it good practice to call matchers from within matchers? Kinda like this pattern: See: committee\_spec.rb · GitHub – Brian

---

## [Testing views of nested resources](https://www.ruby-forum.com/t/testing-views-of-nested-resources/194660)

<div class="topic-metadata">

**Author:** [@Brennon\_B](https://www.ruby-forum.com/u/Brennon_B)\
**Replies:** 1\
**Last updated:** [September 8, 2010, 5:40pm UTC](https://www.ruby-forum.com/t/testing-views-of-nested-resources/194660 "2010-09-08T17:40:02Z")

</div>

I’ve searched and searched, and just can’t find an answer on the list or elsewhere. Forgive me if I’m missing something… I’ve got the following bits of code: app/controllers/widget\_layouts\_controller.rb: class Widget…

---

## [How to wrtie this test?(test true but change when refactor)](https://www.ruby-forum.com/t/how-to-wrtie-this-test-test-true-but-change-when-refactor/194410)

<div class="topic-metadata">

**Author:** [@rubyernewbie](https://www.ruby-forum.com/u/rubyernewbie)\
**Replies:** 7\
**Last updated:** [September 7, 2010, 3:21pm UTC](https://www.ruby-forum.com/t/how-to-wrtie-this-test-test-true-but-change-when-refactor/194410 "2010-09-07T15:21:06Z")

</div>

def process! #transaction block bankbook = self.bankbooks.build bankbook = user.bank.bankbooks.build bankbook.withdraw #end end it “should process the withdrawal request” do #something here omit withdrawal.proce…

---

## [Correct spec for a scoped controller](https://www.ruby-forum.com/t/correct-spec-for-a-scoped-controller/194578)

<div class="topic-metadata">

**Author:** [@fannus](https://www.ruby-forum.com/u/fannus)\
**Replies:** 1\
**Last updated:** [September 7, 2010, 1:58pm UTC](https://www.ruby-forum.com/t/correct-spec-for-a-scoped-controller/194578 "2010-09-07T13:58:33Z")

</div>

In almost all my controllers I scope everything through an @account model object, e.g: #teams\_controller.rb def new @team = @account.teams.build end So far I have got passing specs using these: describe TeamsContr…

---

## [Render\_with\_layout not working with RSpec 2 + Rails 3 + shoulda 2.11.3](https://www.ruby-forum.com/t/render-with-layout-not-working-with-rspec-2-rails-3-shoulda-2-11-3/194527)

<div class="topic-metadata">

**Author:** [@anagri](https://www.ruby-forum.com/u/anagri)\
**Replies:** 1\
**Last updated:** [September 7, 2010, 11:28am UTC](https://www.ruby-forum.com/t/render-with-layout-not-working-with-rspec-2-rails-3-shoulda-2-11-3/194527 "2010-09-07T11:28:40Z")

</div>

Hello, I am trying to assert that my controller is rendered with particular layout file it “should render application layout” do get :index should render\_with\_layout(‘application’) end but it is giving error like …

---

## [\[rspec-autotest\] Autotest is missing some of my specs](https://www.ruby-forum.com/t/rspec-autotest-autotest-is-missing-some-of-my-specs/194520)

<div class="topic-metadata">

**Author:** [@snowbird122](https://www.ruby-forum.com/u/snowbird122)\
**Replies:** 11\
**Last updated:** [September 7, 2010, 9:44am UTC](https://www.ruby-forum.com/t/rspec-autotest-autotest-is-missing-some-of-my-specs/194520 "2010-09-07T09:44:26Z")

</div>

Any idea why autotest would miss some of my tests? I run autotest and everything passes, but rake spec results in 2 failures. The 2 failures are from the model spec that is not being included when run in autotest.

---

## [Render\_template failure](https://www.ruby-forum.com/t/render-template-failure/194465)

<div class="topic-metadata">

**Author:** [@Daniel\_LidstrSSSSm](https://www.ruby-forum.com/u/Daniel_LidstrSSSSm)\
**Replies:** 5\
**Last updated:** [September 7, 2010, 9:44am UTC](https://www.ruby-forum.com/t/render-template-failure/194465 "2010-09-07T09:44:25Z")

</div>

Hello, I am trying to run this integration test of my user controller within a rails 3 application: spec/requests/users\_spec.rb require ‘spec\_helper’ describe “Users” do describe "success" do it "should make a ne…

---

## [How can I set the host for testing subdomain constrained routes in RSpec 2?](https://www.ruby-forum.com/t/how-can-i-set-the-host-for-testing-subdomain-constrained-routes-in-rspec-2/194492)

<div class="topic-metadata">

**Author:** [@DEfusion](https://www.ruby-forum.com/u/DEfusion)\
**Replies:** 2\
**Last updated:** [September 6, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/how-can-i-set-the-host-for-testing-subdomain-constrained-routes-in-rspec-2/194492 "2010-09-06T16:57:39Z")

</div>

I’ve tried: host = ‘foo.bar.com’ host! (undefined method) request.host (request undefined) controller.request.host (controller undefined) @controller.request.host (undefined method \`request’ for nil:NilClass)

---

## [Should contain vs. =~](https://www.ruby-forum.com/t/should-contain-vs/194500)

<div class="topic-metadata">

**Author:** [@Brennon\_B](https://www.ruby-forum.com/u/Brennon_B)\
**Replies:** 6\
**Last updated:** [September 6, 2010, 4:51pm UTC](https://www.ruby-forum.com/t/should-contain-vs/194500 "2010-09-06T16:51:47Z")

</div>

I’m developing another view test. Relevant example: it “should show the item’s url” do rendered.should contain(“http://www.example.com”) end I’m calling render in a before block. I have other similar examples on t…

---

## [How to invoke multiple controllers in the same describe block?](https://www.ruby-forum.com/t/how-to-invoke-multiple-controllers-in-the-same-describe-block/194503)

<div class="topic-metadata">

**Author:** [@Lille](https://www.ruby-forum.com/u/Lille)\
**Replies:** 2\
**Last updated:** [September 6, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/how-to-invoke-multiple-controllers-in-the-same-describe-block/194503 "2010-09-06T16:44:09Z")

</div>

Hi, I seek to authenticate and then test other routing in RSpec, but the standard RSpec vernacular… describe SomeController do it “blah-blah” do get :new … end end …doesn’t seem to allow me to post my login data…

---

## [\[Rails\] \[Bug\] use\_transactional\_fixtures = false suppress the 'fixtures' method](https://www.ruby-forum.com/t/rails-bug-use-transactional-fixtures-false-suppress-the-fixtures-method/194455)

<div class="topic-metadata">

**Author:** [@Lailson\_B](https://www.ruby-forum.com/u/Lailson_B)\
**Replies:** 3\
**Last updated:** [September 6, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/rails-bug-use-transactional-fixtures-false-suppress-the-fixtures-method/194455 "2010-09-06T16:44:09Z")

</div>

Hi folks, I’m having a problem with fixtures. When I configure RSpec to don’t use transactional fixtures, the fixtures method goes away. Supposing there’s a State model and a fixture file with two records, this work…

---

## [Error when trying to run rspec](https://www.ruby-forum.com/t/error-when-trying-to-run-rspec/194501)

<div class="topic-metadata">

**Author:** [@dangermoose](https://www.ruby-forum.com/u/dangermoose)\
**Replies:** 1\
**Last updated:** [September 6, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/error-when-trying-to-run-rspec/194501 "2010-09-06T16:44:07Z")

</div>

Just tried to run rspec and got this error message even though the rspec gem installed successfully: $ spec hello\_spec.rb /Users/pdenlinger/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/rubygems.rb: 340:in bin\_path': can'…

---

## [Rails3/rspec2: how to write mailer tests?](https://www.ruby-forum.com/t/rails3-rspec2-how-to-write-mailer-tests/194338)

<div class="topic-metadata">

**Author:** [@nathanvda](https://www.ruby-forum.com/u/nathanvda)\
**Replies:** 5\
**Last updated:** [September 2, 2010, 5:24pm UTC](https://www.ruby-forum.com/t/rails3-rspec2-how-to-write-mailer-tests/194338 "2010-09-02T17:24:47Z")

</div>

This will sound awfully stupid, but i have no idea how to start writing any mailer tests. I have a mailer class class SmsMailer \< ActionMailer::Base def fake\_sms(envelope) mail(:to =\> envelope.user.email) end…

---

## [Undefined methods: has\_selector? and flunk](https://www.ruby-forum.com/t/undefined-methods-has-selector-and-flunk/194240)

<div class="topic-metadata">

**Author:** [@wickie](https://www.ruby-forum.com/u/wickie)\
**Replies:** 2\
**Last updated:** [September 1, 2010, 3:47pm UTC](https://www.ruby-forum.com/t/undefined-methods-has-selector-and-flunk/194240 "2010-09-01T15:47:53Z")

</div>

I’m in the process of updating an app for Rails 3.0 and rspec-rails 2.0.0.beta20. When I’m running my specs (rake spec) I get a large number of errors caused by two undefined methods undefined method \`has\_selector?’ f…

---

## [Rspec2: autotest keeps rerunning failing tests](https://www.ruby-forum.com/t/rspec2-autotest-keeps-rerunning-failing-tests/194098)

<div class="topic-metadata">

**Author:** [@nathanvda](https://www.ruby-forum.com/u/nathanvda)\
**Replies:** 9\
**Last updated:** [September 1, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/rspec2-autotest-keeps-rerunning-failing-tests/194098 "2010-09-01T15:08:39Z")

</div>

Since my update to beta.20 i have this weird thing. Normally i develop with autotest on, and when i get an error: i can check the errors, and they are rerun when i save the files. If all my tests pass this is still th…

---

## [Global before block for specific spec type](https://www.ruby-forum.com/t/global-before-block-for-specific-spec-type/194191)

<div class="topic-metadata">

**Author:** [@rubyfox](https://www.ruby-forum.com/u/rubyfox)\
**Replies:** 1\
**Last updated:** [August 31, 2010, 8:48pm UTC](https://www.ruby-forum.com/t/global-before-block-for-specific-spec-type/194191 "2010-08-31T20:48:06Z")

</div>

So previously it seems it was possible to configure global before block which will get run, say only for controller specs (people even used that I think ) Now I wasn’t able to find anything like that, and the close…

---

## [Factories vs. stubs/mocks](https://www.ruby-forum.com/t/factories-vs-stubs-mocks/194118)

<div class="topic-metadata">

**Author:** [@Brennon\_B](https://www.ruby-forum.com/u/Brennon_B)\
**Replies:** 8\
**Last updated:** [August 31, 2010, 11:16am UTC](https://www.ruby-forum.com/t/factories-vs-stubs-mocks/194118 "2010-08-31T11:16:05Z")

</div>

I am, as usual, assigning an instance variable in a controller’s index action to find all instances of a model in the database. I want to write a spec that checks that this variable is assigned correctly. I can do: …

---

## [Rspec2 ETA?](https://www.ruby-forum.com/t/rspec2-eta/194088)

<div class="topic-metadata">

**Author:** [@arco](https://www.ruby-forum.com/u/arco)\
**Replies:** 2\
**Last updated:** [August 30, 2010, 3:52pm UTC](https://www.ruby-forum.com/t/rspec2-eta/194088 "2010-08-30T15:52:08Z")

</div>

Is there an ETA for a production version of Rspec2 ??

---

## [Default format for all requests in a spec](https://www.ruby-forum.com/t/default-format-for-all-requests-in-a-spec/193915)

<div class="topic-metadata">

**Author:** [@mauricio](https://www.ruby-forum.com/u/mauricio)\
**Replies:** 3\
**Last updated:** [August 30, 2010, 3:24pm UTC](https://www.ruby-forum.com/t/default-format-for-all-requests-in-a-spec/193915 "2010-08-30T15:24:01Z")

</div>

Hi guys, Is there a way to define a default parameter for all requests made in a spec? I have a spec where I want all requests to be made with the “js” format but I find it rather annoying to type a “:format =\> ‘js’”…

---

## [Respond\_to? check in rspec-mocks](https://www.ruby-forum.com/t/respond-to-check-in-rspec-mocks/194016)

<div class="topic-metadata">

**Author:** [@Myron\_M](https://www.ruby-forum.com/u/Myron_M)\
**Replies:** 11\
**Last updated:** [August 30, 2010, 12:52am UTC](https://www.ruby-forum.com/t/respond-to-check-in-rspec-mocks/194016 "2010-08-30T00:52:25Z")

</div>

One of the primary dangers of using mocks is that your unit tests may be testing against an interface that is different from that of your production objects. You may simply have misspelled the method (e.g. object.sho…

---

## [RSpec 2/Rails 3 - content\_for in view specs](https://www.ruby-forum.com/t/rspec-2-rails-3-content-for-in-view-specs/193514)

<div class="topic-metadata">

**Author:** [@dmarkow](https://www.ruby-forum.com/u/dmarkow)\
**Replies:** 1\
**Last updated:** [August 29, 2010, 1:24am UTC](https://www.ruby-forum.com/t/rspec-2-rails-3-content-for-in-view-specs/193514 "2010-08-29T01:24:49Z")

</div>

My main layout includes separate content\_for/yield sections for my header, sidebar, footer, and content. However, when running a view spec, the rendered variable seems to only contain a string of just the primary con…

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

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