# RSpec

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

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

---

## [Anonymous Subclass of ActionController::Base](https://www.ruby-forum.com/t/anonymous-subclass-of-actioncontroller-base/205147)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 0\
**Last updated:** [March 30, 2011, 6:05pm UTC](https://www.ruby-forum.com/t/anonymous-subclass-of-actioncontroller-base/205147 "2011-03-30T18:05:30Z")

</div>

I’m trying to spec a subclass of ActionController::Base using an anonymous subclass but I am running into errors but I am receiving a uninitialized constant StubResource Here is my base class class Admin::BaseControl…

---

## [Stubbing mongoid::criteria in view code](https://www.ruby-forum.com/t/stubbing-mongoid-criteria-in-view-code/204910)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 4\
**Last updated:** [March 29, 2011, 10:18pm UTC](https://www.ruby-forum.com/t/stubbing-mongoid-criteria-in-view-code/204910 "2011-03-29T22:18:18Z")

</div>

I’m try to stub the following in my view code but keep running into problems with unexpected messages. I’ve tried stubbing and mocking in many combinations but can’t find away past this. Here is the code below I am tr…

---

## [Given-when-then-and syntax support in Rspec](https://www.ruby-forum.com/t/given-when-then-and-syntax-support-in-rspec/205015)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 7\
**Last updated:** [March 28, 2011, 6:56am UTC](https://www.ruby-forum.com/t/given-when-then-and-syntax-support-in-rspec/205015 "2011-03-28T06:56:46Z")

</div>

Hi David and fellows, I know this subject has already been discussed here and there are already some attempts to support the given-when-then-and syntax in Rspec, like the links below: First, I don’t understand the…

---

## [Calbacks on models](https://www.ruby-forum.com/t/calbacks-on-models/203974)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 6\
**Last updated:** [March 27, 2011, 6:39pm UTC](https://www.ruby-forum.com/t/calbacks-on-models/203974 "2011-03-27T18:39:16Z")

</div>

Hi, I’m having some strange behavior on callbacks when testing with RSpec2. On my test, when I create a resource using the #create method the callbacks related to #before\_create are not called. If I go to the console …

---

## [How do I use expect{}.to change().from().to() on Array?](https://www.ruby-forum.com/t/how-do-i-use-expect-to-change-from-to-on-array/204562)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 6\
**Last updated:** [March 26, 2011, 2:04am UTC](https://www.ruby-forum.com/t/how-do-i-use-expect-to-change-from-to-on-array/204562 "2011-03-26T02:04:32Z")

</div>

Hi. I’m using ruby1.9.2 and rspec2.5.1 I want to use “expect{}.to change().from().to()” like this When Int class, it passed. When Ary class, it failed. Why was Ary test failed and How do I pass this test? regards…

---

## [Equivalency testing for XML](https://www.ruby-forum.com/t/equivalency-testing-for-xml/204914)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [March 25, 2011, 5:59am UTC](https://www.ruby-forum.com/t/equivalency-testing-for-xml/204914 "2011-03-25T05:59:36Z")

</div>

Hello all, I recently released a gem that assists in testing XML nodes for equivalency, and thought it might be of interest to the RSpec community. It can normalize whitespace (or not), ignore element order (or not)…

---

## [How to test a Rails 3 metal controller?](https://www.ruby-forum.com/t/how-to-test-a-rails-3-metal-controller/204821)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 2\
**Last updated:** [March 24, 2011, 12:14pm UTC](https://www.ruby-forum.com/t/how-to-test-a-rails-3-metal-controller/204821 "2011-03-24T12:14:50Z")

</div>

Hi! I could not find an easy solution to this question: how can I properly test an Rails controller action? We were trying to run the following test: get :show, :id =\> 'hello' response.should redirect\_to("http://www.…

---

## [Re: Post call verification](https://www.ruby-forum.com/t/re-post-call-verification/204871)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 2\
**Last updated:** [March 23, 2011, 8:57pm UTC](https://www.ruby-forum.com/t/re-post-call-verification/204871 "2011-03-23T20:57:48Z")

</div>

If anyone is interested, I wrote a quick little gem to add spies to rspec-mocks. Basically, it adds a method called spy which internally returns a mock.as\_null\_object, and a matcher for “have\_received(:method)” & “ha…

---

## [Testing routes with a prefix](https://www.ruby-forum.com/t/testing-routes-with-a-prefix/204837)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 5\
**Last updated:** [March 23, 2011, 7:47pm UTC](https://www.ruby-forum.com/t/testing-routes-with-a-prefix/204837 "2011-03-23T19:47:33Z")

</div>

Hi experts, I am trying to test routing in my application, where all routes are enclosed in a namespace like so: scope ‘v1’ do resource :blah end collection do something end end end Is there a clean way to set …

---

## [Current example](https://www.ruby-forum.com/t/current-example/204862)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [March 23, 2011, 3:26pm UTC](https://www.ruby-forum.com/t/current-example/204862 "2011-03-23T15:26:24Z")

</div>

Is it possible to retrieve the example that is currently running?

---

## [Model validation failing in rspec for unknown reason](https://www.ruby-forum.com/t/model-validation-failing-in-rspec-for-unknown-reason/202903)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 3\
**Last updated:** [March 23, 2011, 6:31am UTC](https://www.ruby-forum.com/t/model-validation-failing-in-rspec-for-unknown-reason/202903 "2011-03-23T06:31:40Z")

</div>

Hi, i’m getting the following error when running a spec on my controller for my Equipment model. it "edit action should render edit template" do get :edit, :id =\> Factory(:equipment) response.should render\_template…

---

## [Is it possible to run rspec continuously?](https://www.ruby-forum.com/t/is-it-possible-to-run-rspec-continuously/204832)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 3\
**Last updated:** [March 22, 2011, 11:42pm UTC](https://www.ruby-forum.com/t/is-it-possible-to-run-rspec-continuously/204832 "2011-03-22T23:42:07Z")

</div>

When I run rspec in Rails, it seems that a ruby process is created and loaded with rails components due to the statement require ‘spec\_helper’. This usually takes a while to run even a single spec. Does a tool for rsp…

---

## [Post call verification](https://www.ruby-forum.com/t/post-call-verification/204711)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 4\
**Last updated:** [March 22, 2011, 10:31am UTC](https://www.ruby-forum.com/t/post-call-verification/204711 "2011-03-22T10:31:27Z")

</div>

Hey all, I would like to be able to be able to have mocks where I can make all the calls and assert that it was called afterwards. This would be especially useful when asserting on a doing-method whose return value is …

---

## [Stub a controllers helper\_method in a view template helper spec](https://www.ruby-forum.com/t/stub-a-controllers-helper-method-in-a-view-template-helper-spec/204770)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 13\
**Last updated:** [March 21, 2011, 10:31pm UTC](https://www.ruby-forum.com/t/stub-a-controllers-helper-method-in-a-view-template-helper-spec/204770 "2011-03-21T22:31:50Z")

</div>

My ApplicationController exposes a method (e.g. sort\_direction) to the view templates by using helper\_method :sort\_direction. I then use this method in another method (e.g. sort\_link) in a view helper (application\_he…

---

## [Rake spec loads development environment](https://www.ruby-forum.com/t/rake-spec-loads-development-environment/146285)

<div class="topic-metadata">

**Author:** [@satishg](https://www.ruby-forum.com/u/satishg)\
**Replies:** 16\
**Last updated:** [March 21, 2011, 7:04pm UTC](https://www.ruby-forum.com/t/rake-spec-loads-development-environment/146285 "2011-03-21T19:04:44Z")

</div>

Hi, I am new to rspec and started implementing it on my project yesterday. I have followed the instructions and installed rspec gem and rspec plugin into my project. I created couple of sample stories and tried runni…

---

## [RSpec & DataMapper Open Source Projects?](https://www.ruby-forum.com/t/rspec-datamapper-open-source-projects/204589)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [March 21, 2011, 12:39pm UTC](https://www.ruby-forum.com/t/rspec-datamapper-open-source-projects/204589 "2011-03-21T12:39:11Z")

</div>

Hi there, Does anyone know of any open source projects that are using RSpec and DataMapper together that I can dissect? Thanks. Sid

---

## [\[rspec-rails\] warning about polymorphism on child objects](https://www.ruby-forum.com/t/rspec-rails-warning-about-polymorphism-on-child-objects/204713)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [March 20, 2011, 4:04pm UTC](https://www.ruby-forum.com/t/rspec-rails-warning-about-polymorphism-on-child-objects/204713 "2011-03-20T16:04:04Z")

</div>

Hi, I just ran into kind of an issue with child models in a one-to-one relationship who are also in a polymorphic association, i.e., their foreign key is kept by another model, e.g., ‘Comment’. So, the path for a chi…

---

## [Controller Spec & DataMapper Chaining](https://www.ruby-forum.com/t/controller-spec-datamapper-chaining/204684)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 7\
**Last updated:** [March 20, 2011, 12:27am UTC](https://www.ruby-forum.com/t/controller-spec-datamapper-chaining/204684 "2011-03-20T00:27:53Z")

</div>

Hi there, I’m fairly new to RSpec, and DataMapper and I’m trying to write a controller spec for an index action that will include DM query chaining. Here is a very simplified version of the Controller#index I’m worki…

---

## [Experimenting with stub in irb with RSpec2](https://www.ruby-forum.com/t/experimenting-with-stub-in-irb-with-rspec2/199164)

<div class="topic-metadata">

**Author:** [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Replies:** 3\
**Last updated:** [March 20, 2011, 12:22am UTC](https://www.ruby-forum.com/t/experimenting-with-stub-in-irb-with-rspec2/199164 "2011-03-20T00:22:32Z")

</div>

In class, to give people a feel for how stubs work, I used to do this with rspec 1.x: sarah:~$ gem list rspec \*\*\* LOCAL GEMS \*\*\* rspec (1.3.0) rspec-rails (1.3.2) sarah:~$ ruby -v ruby 1.8.7 (2009-06-12 patchlevel…

---

## [Custom matcher and yielding too block](https://www.ruby-forum.com/t/custom-matcher-and-yielding-too-block/204710)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [March 19, 2011, 2:02pm UTC](https://www.ruby-forum.com/t/custom-matcher-and-yielding-too-block/204710 "2011-03-19T14:02:57Z")

</div>

Using the ‘new’ way of defining custom matchers explained here: I’m having trouble figuring out how to write a custom matcher that yields an object to a block where more matchers can be called on it. For instance, I’…

---

## [RSpec2 collides with Runt but why?](https://www.ruby-forum.com/t/rspec2-collides-with-runt-but-why/204701)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [March 19, 2011, 2:55am UTC](https://www.ruby-forum.com/t/rspec2-collides-with-runt-but-why/204701 "2011-03-19T02:55:57Z")

</div>

Hi, A project of mine is using Runt expressions to match dates. When upgraded my rake tasks to 2.5.1 (from 1.3.0) it get this /usr/bin/ruby1.8 -S rspec spec/delivery\_spec.rb spec/reporter\_spec.rb spec/mysql\_dump\_spec…

---

## [Rails 3 Upgrade](https://www.ruby-forum.com/t/rails-3-upgrade/204120)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 4\
**Last updated:** [March 18, 2011, 8:15pm UTC](https://www.ruby-forum.com/t/rails-3-upgrade/204120 "2011-03-18T20:15:59Z")

</div>

Hi, I am upgrading a rails 2.1.0 app to Rails 3. Before I started my migration, I wrote all the tests cases for my app in Rspec 1.x version. I am doubting whether rspec test cases written in 1.x version will work whe…

---

## ['spec' command not working](https://www.ruby-forum.com/t/spec-command-not-working/204665)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 6\
**Last updated:** [March 18, 2011, 6:08pm UTC](https://www.ruby-forum.com/t/spec-command-not-working/204665 "2011-03-18T18:08:55Z")

</div>

When I run JSpec, in the command prompt, using the “spec” command, I get this error: ‘spec’ command not recognized as a command I have the latest versions of JSpec and Ruby installed. How can I use the spec command? …

---

## [Functional Tests with custom routes](https://www.ruby-forum.com/t/functional-tests-with-custom-routes/204686)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [March 18, 2011, 4:46pm UTC](https://www.ruby-forum.com/t/functional-tests-with-custom-routes/204686 "2011-03-18T16:46:43Z")

</div>

Say I have a custom route like this… map.connect ‘item/:id/some\_action’, :controller =\> ‘object’, :action =\> ‘change\_color’, :conditions =\> {:method =\> :put} I’ve been writing my tests like this… describe ObjectContr…

---

## [Are there any ways to detect spec faults during a run?](https://www.ruby-forum.com/t/are-there-any-ways-to-detect-spec-faults-during-a-run/229197)

<div class="topic-metadata">

**Author:** [@Magnus\_Erickson](https://www.ruby-forum.com/u/Magnus_Erickson)\
**Replies:** 4\
**Last updated:** [March 18, 2011, 4:22pm UTC](https://www.ruby-forum.com/t/are-there-any-ways-to-detect-spec-faults-during-a-run/229197 "2011-03-18T16:22:54Z")

</div>

Hi, Is there a way to detect if an example has failed? Something like a: “example\_failed?” method. In my case I need to dump some information, i.e trace and error log, to be used when analyzing what went wrong in t…

---

## [Counter.should\_not\_receive(:message) not working?](https://www.ruby-forum.com/t/counter-should-not-receive-message-not-working/204658)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 5\
**Last updated:** [March 18, 2011, 1:54am UTC](https://www.ruby-forum.com/t/counter-should-not-receive-message-not-working/204658 "2011-03-18T01:54:18Z")

</div>

I’m trying to test a Rails controller and am having trouble getting SHOULD\_NOT\_RECEIVE to work on a class method. I can never get Counter.should\_not\_receive(:xxx) to fail when the message ‘xxx’ is sent. Controller: d…

---

## [Testing route with proc --- possible and how?](https://www.ruby-forum.com/t/testing-route-with-proc-possible-and-how/204660)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 0\
**Last updated:** [March 17, 2011, 9:14pm UTC](https://www.ruby-forum.com/t/testing-route-with-proc-possible-and-how/204660 "2011-03-17T21:14:15Z")

</div>

I have this route (Rails 3) which handles redirecting shortened urls: handles the shortened url lookup match ‘:hash’ =\> redirect { |params| Sharing.get\_url\_path\_by\_short\_url(params\[:hash\]) }, :constraints =\> { :hash …

---

## [Autotest missing specs, not missed in rake spec](https://www.ruby-forum.com/t/autotest-missing-specs-not-missed-in-rake-spec/204648)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [March 17, 2011, 6:26pm UTC](https://www.ruby-forum.com/t/autotest-missing-specs-not-missed-in-rake-spec/204648 "2011-03-17T18:26:41Z")

</div>

I’ve included the output from running my specs with rake spec and autotest. I’ve restarted autotest several times to no avail. For some reason, autotest is missing the newsroom\_blog\_post specs. Any idea how to reso…

---

## [Issues implementing Rspec with Rails3 from tutorial](https://www.ruby-forum.com/t/issues-implementing-rspec-with-rails3-from-tutorial/204362)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 2\
**Last updated:** [March 16, 2011, 5:53pm UTC](https://www.ruby-forum.com/t/issues-implementing-rspec-with-rails3-from-tutorial/204362 "2011-03-16T17:53:42Z")

</div>

Hi, I am a newbie to Rails 3 and Rspec. Kindly excuse my being a novice. I am trying to implement RSpec with Rails 3. I am using Rails 3.0.3 with Ruby 1.9.2 on Ubuntu 10.04 os. I am using rspec 2.5 gem and rspec-rails …

---

## [Unless filter](https://www.ruby-forum.com/t/unless-filter/204350)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 4\
**Last updated:** [March 15, 2011, 1:04pm UTC](https://www.ruby-forum.com/t/unless-filter/204350 "2011-03-15T13:04:12Z")

</div>

Hi. Why doesn’t the following filter work? # encoding: utf-8 # ./example\_spec.rb RSpec.configure do |config| config.filter = { unless: :condition\_acceptable } end describe 'some code' do it 'does one', if: …

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

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