# RSpec

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

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

---

## [Understanding rspec predicates](https://www.ruby-forum.com/t/understanding-rspec-predicates/212689)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 6\
**Last updated:** [October 12, 2011, 3:50am UTC](https://www.ruby-forum.com/t/understanding-rspec-predicates/212689 "2011-10-12T03:50:13Z")

</div>

I know I can do: blah.should be\_empty or blah.should have\_key(:to\_my\_house) … But, is there a way to do: str = “lmaonade omg rotfcopter!” str.should start\_with(“lmao”) Or is it just best to do: str.starts\_with?(…

---

## [Rspec dry run](https://www.ruby-forum.com/t/rspec-dry-run/212702)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 0\
**Last updated:** [October 11, 2011, 1:52pm UTC](https://www.ruby-forum.com/t/rspec-dry-run/212702 "2011-10-11T13:52:06Z")

</div>

We count how many examples before start executing example, we used to use --dry–run option to achieve this. Now dry run is removed in Rspec 2, do you have a way that we can count examples without executing examples? T…

---

## [Testing a render of a partial in a helper](https://www.ruby-forum.com/t/testing-a-render-of-a-partial-in-a-helper/212530)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [October 11, 2011, 1:21pm UTC](https://www.ruby-forum.com/t/testing-a-render-of-a-partial-in-a-helper/212530 "2011-10-11T13:21:07Z")

</div>

I am trying to spec my helpers, and I find a few of my helpers actually render a partial. My code: module PageHelper def settings\_menu render :partial =\> '\_shared/settings\_menu' end def banner\_for(model) …

---

## [Assertions for asynchronous behaviour](https://www.ruby-forum.com/t/assertions-for-asynchronous-behaviour/211775)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 12\
**Last updated:** [October 3, 2011, 12:03am UTC](https://www.ruby-forum.com/t/assertions-for-asynchronous-behaviour/211775 "2011-10-03T00:03:21Z")

</div>

Hi all, In GOOS\[1\] they use an assertion called assertEventually which samples the system for a success state until a certain timeout has elapsed. This allows you to synchronise the tests with asynchronous code. Do w…

---

## [Override tests (of a core rails app from a plugin)](https://www.ruby-forum.com/t/override-tests-of-a-core-rails-app-from-a-plugin/212417)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 4\
**Last updated:** [October 2, 2011, 10:17pm UTC](https://www.ruby-forum.com/t/override-tests-of-a-core-rails-app-from-a-plugin/212417 "2011-10-02T22:17:15Z")

</div>

Hello, Is there some way to override a spec and more specifically parts of spec, ideally down to a specific example? I’ve been looking and googling for something like this, but I haven’t found a good strategy for it. …

---

## [Let vs ivar w/ before block](https://www.ruby-forum.com/t/let-vs-ivar-w-before-block/212365)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 9\
**Last updated:** [October 1, 2011, 1:30pm UTC](https://www.ruby-forum.com/t/let-vs-ivar-w-before-block/212365 "2011-10-01T13:30:41Z")

</div>

Am I correct in understanding that the point of using let is that it can minimize database calls due to memoization? describe “#something” do let(:something) = Something.groovy\_scope it “does x” do something.first.x…

---

## [Custom Formatter: Getting Text from It Method](https://www.ruby-forum.com/t/custom-formatter-getting-text-from-it-method/212362)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 2\
**Last updated:** [October 1, 2011, 4:37am UTC](https://www.ruby-forum.com/t/custom-formatter-getting-text-from-it-method/212362 "2011-10-01T04:37:05Z")

</div>

Hey all. I’ve been playing around with RSpec custom formatters to see how much flexibility there is. One thing I’ve been trying to see is if I can print the contents of a variable that’s in an example (it) method. So, …

---

## [Uninitialized constant Spec::Rails (NameError) when running spec command](https://www.ruby-forum.com/t/uninitialized-constant-spec-rails-nameerror-when-running-spec-command/212119)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 3\
**Last updated:** [September 27, 2011, 1:06pm UTC](https://www.ruby-forum.com/t/uninitialized-constant-spec-rails-nameerror-when-running-spec-command/212119 "2011-09-27T13:06:35Z")

</div>

I get the following error when trying to run a spec command on a model test. The command is :- C:\\Rspec Test\\spec\\models\>spec bank\_account\_spec.rb The error is :- c:/jruby-1.5.0/lib/ruby/gems/1.8/gems/rspec-rails-1.3…

---

## [Running rspec alongside test::unit?](https://www.ruby-forum.com/t/running-rspec-alongside-test-unit/212015)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 27, 2011, 10:58am UTC](https://www.ruby-forum.com/t/running-rspec-alongside-test-unit/212015 "2011-09-27T10:58:33Z")

</div>

Earlier documentation indicated that it was possible to run RSpec alongside existing test::unit tests. Is this still possible? – Jason P.

---

## [How to test identical behavior without being redundant?](https://www.ruby-forum.com/t/how-to-test-identical-behavior-without-being-redundant/212247)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 27, 2011, 12:06am UTC](https://www.ruby-forum.com/t/how-to-test-identical-behavior-without-being-redundant/212247 "2011-09-27T00:06:42Z")

</div>

I’ve got many models that have this declared: has\_many :notifications, :as =\> :notifiable, :dependent =\> :destroy … And so I have many model specs such as: describe Reply do it “should eliminate any associated notif…

---

## [Redirecting from rspec.info to relishapp.com/rspec](https://www.ruby-forum.com/t/redirecting-from-rspec-info-to-relishapp-com-rspec/212194)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 25, 2011, 9:37am UTC](https://www.ruby-forum.com/t/redirecting-from-rspec-info-to-relishapp-com-rspec/212194 "2011-09-25T09:37:29Z")

</div>

I’m interested in writing a redirect app from rspec.info (rspec 1.0) to relishapp.com/rspec (rspec 2). Can someone tell me who I would contact to get the information I need (what old links need to redirect to where, e…

---

## [Shared examples in test unit?](https://www.ruby-forum.com/t/shared-examples-in-test-unit/212192)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [September 25, 2011, 9:27am UTC](https://www.ruby-forum.com/t/shared-examples-in-test-unit/212192 "2011-09-25T09:27:37Z")

</div>

hi, at work we use TestUnit, and I miss there a lot the shared\_examples from RSpec, do you know if is there something alike for TestUnit? I know this might be a bit OT but I thought you probably might know :slight\_smi…

---

## [How to stub ApplicationController method in request spec](https://www.ruby-forum.com/t/how-to-stub-applicationcontroller-method-in-request-spec/212193)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 25, 2011, 9:16am UTC](https://www.ruby-forum.com/t/how-to-stub-applicationcontroller-method-in-request-spec/212193 "2011-09-25T09:16:33Z")

</div>

Hey there, I am needing to stub a ‘current\_user’ method in an Rspec/capybara request spec. The method is defined in ApplicationController and is using helper\_method. The method should simply return a user id. Alterna…

---

## [Preferred place for methods used by both rspec and cucumber?](https://www.ruby-forum.com/t/preferred-place-for-methods-used-by-both-rspec-and-cucumber/212101)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 3\
**Last updated:** [September 23, 2011, 7:46pm UTC](https://www.ruby-forum.com/t/preferred-place-for-methods-used-by-both-rspec-and-cucumber/212101 "2011-09-23T19:46:18Z")

</div>

Hi, I have some helper methods such as: def mock\_omniauth OmniAuth.config.test\_mode = true OmniAuth.config.mock\_auth\[:facebook\] = facebook\_user end def facebook\_user @facebook\_user ||= HashWithIndifferentAccess.n…

---

## [Using rspec to verify an xpath (via capybara/cucumber)](https://www.ruby-forum.com/t/using-rspec-to-verify-an-xpath-via-capybara-cucumber/212056)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 2\
**Last updated:** [September 21, 2011, 12:26am UTC](https://www.ruby-forum.com/t/using-rspec-to-verify-an-xpath-via-capybara-cucumber/212056 "2011-09-21T00:26:11Z")

</div>

I am doing: page.should have\_xpath(“//img\[contains(@class, ‘foobar’)\]”, :count =\> 0) but cucumber tells me: expected xpath “//img\[contains(@class, ‘foobar’)\]” to return something (RSpec::Expectations::ExpectationNot…

---

## [Mocking expectations on I/O operations](https://www.ruby-forum.com/t/mocking-expectations-on-i-o-operations/211817)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 8\
**Last updated:** [September 16, 2011, 3:51pm UTC](https://www.ruby-forum.com/t/mocking-expectations-on-i-o-operations/211817 "2011-09-16T15:51:00Z")

</div>

I’m speccing a small lib which manipulates image files using mini\_magick. The lib creates various temporary files during the process, the lib then cleans up the temporary files at the end. I’m trying to mock expectat…

---

## [Rspec not recognised](https://www.ruby-forum.com/t/rspec-not-recognised/211861)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 15, 2011, 1:07pm UTC](https://www.ruby-forum.com/t/rspec-not-recognised/211861 "2011-09-15T13:07:49Z")

</div>

Hi, I am using Rails 3 and rspec-rails gem. When try to run rspec spec\\models\\profile.rb I get result as follows: ‘rspec’ is not recognized as an internal or external command, Can you help? Thanks, Aashish

---

## [Rspec error while running jruby -S rake spec](https://www.ruby-forum.com/t/rspec-error-while-running-jruby-s-rake-spec/211727)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 4\
**Last updated:** [September 15, 2011, 12:15pm UTC](https://www.ruby-forum.com/t/rspec-error-while-running-jruby-s-rake-spec/211727 "2011-09-15T12:15:49Z")

</div>

Hello All, I followed steps to install Rspec as in the link pasted below. http://www.pmamediagroup.com/2009/04/tutorial-install-rspec-rails-factory-girl/ I have jRuby on Rails installed on my machine.Hence all command…

---

## [Rspec and should have\_many through](https://www.ruby-forum.com/t/rspec-and-should-have-many-through/211804)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 14, 2011, 3:45am UTC](https://www.ruby-forum.com/t/rspec-and-should-have-many-through/211804 "2011-09-14T03:45:26Z")

</div>

Hi, Anyone can help me with rspec shoulda validations please. I can’t get the syntax right for these validations. Please correct me it { should have\_one :tradable, :through =\> :trade\_order} it { should belong\_to :sou…

---

## [Generate user-readable tests from Rspec tests?](https://www.ruby-forum.com/t/generate-user-readable-tests-from-rspec-tests/211713)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 4\
**Last updated:** [September 13, 2011, 12:03pm UTC](https://www.ruby-forum.com/t/generate-user-readable-tests-from-rspec-tests/211713 "2011-09-13T12:03:39Z")

</div>

I have been writing manual tests and dabbled in Cucumber. I like that end users can read the Cucumber tests. Is there a way to generate user-readable tests from Rspec tests or Watir tests? Thank you.

---

## [How can I get rspec to generate files with rails g model?](https://www.ruby-forum.com/t/how-can-i-get-rspec-to-generate-files-with-rails-g-model/211754)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 1\
**Last updated:** [September 13, 2011, 8:13am UTC](https://www.ruby-forum.com/t/how-can-i-get-rspec-to-generate-files-with-rails-g-model/211754 "2011-09-13T08:13:10Z")

</div>

I just added RSpec 2 to a project that has been using test::unit, and I was wondering how to get RSpec to automatically build test files for my models? when I do rails g rspec:model foo, I just get see CREATE spec/m…

---

## [Rspec rake task + bundler: feedback requested](https://www.ruby-forum.com/t/rspec-rake-task-bundler-feedback-requested/211639)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 0\
**Last updated:** [September 9, 2011, 3:28pm UTC](https://www.ruby-forum.com/t/rspec-rake-task-bundler-feedback-requested/211639 "2011-09-09T15:28:53Z")

</div>

Hey folks, RSpec’s assumption that the existence of a Gemfile means you want to use Bundler to configure runtime environment is flawed. We added a skip\_bundler option to the rake task, but that was a temporary hack to …

---

## [Rendering xml with haml through render\_template is invalid](https://www.ruby-forum.com/t/rendering-xml-with-haml-through-render-template-is-invalid/211618)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 9, 2011, 7:19am UTC](https://www.ruby-forum.com/t/rendering-xml-with-haml-through-render-template-is-invalid/211618 "2011-09-09T07:19:06Z")

</div>

I have some controller tests for validity of restful XML responses. I’m using haml to generate the xml. When I test externally with curl the response is well-formed XML. However when I test the controllers with rspec2…

---

## [Rspec and testing IO](https://www.ruby-forum.com/t/rspec-and-testing-io/211617)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 0\
**Last updated:** [September 9, 2011, 5:16am UTC](https://www.ruby-forum.com/t/rspec-and-testing-io/211617 "2011-09-09T05:16:45Z")

</div>

Thanks Justin, that’ll work just fine for my simple case and, in the mean time, I’ll look in to aruba also. Much appreciated! Justin

---

## [Rspec and testing IO](https://www.ruby-forum.com/t/rspec-and-testing-io/211615)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 1\
**Last updated:** [September 9, 2011, 3:08am UTC](https://www.ruby-forum.com/t/rspec-and-testing-io/211615 "2011-09-09T03:08:57Z")

</div>

I have a class that expects some input via ‘gets’. I found that, when testing, I can do something as simple as this: @foo.stub!(:gets) { “stuff\\n” } However that only works in the most simple case. In my case the cl…

---

## [Is there a way to get an "around" hook for each spec file?](https://www.ruby-forum.com/t/is-there-a-way-to-get-an-around-hook-for-each-spec-file/211572)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 3\
**Last updated:** [September 7, 2011, 5:33pm UTC](https://www.ruby-forum.com/t/is-there-a-way-to-get-an-around-hook-for-each-spec-file/211572 "2011-09-07T17:33:04Z")

</div>

Is there a way to run an around block once for every spec file (not spec)? (I want to measure which files take the longest amount of time, count the number of specs in each file, and then report the average spec runni…

---

## [Warning (but not failing) if a method wasn't called?](https://www.ruby-forum.com/t/warning-but-not-failing-if-a-method-wasnt-called/211571)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 2\
**Last updated:** [September 7, 2011, 4:36pm UTC](https://www.ruby-forum.com/t/warning-but-not-failing-if-a-method-wasnt-called/211571 "2011-09-07T16:36:07Z")

</div>

Is there a way to warn but not fail if a particular method wasn’t called? That is, I’m looking for something that’s halfway between obj.stub(…) and obj.should\_receive(…). I’m trying to do something like this: shared\_…

---

## [Rspec testing inheritance](https://www.ruby-forum.com/t/rspec-testing-inheritance/211556)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 4\
**Last updated:** [September 7, 2011, 4:01pm UTC](https://www.ruby-forum.com/t/rspec-testing-inheritance/211556 "2011-09-07T16:01:29Z")

</div>

Hello, Is there any way to test model inheritance in spec? something like… it { ChildModel.should \< ParentModel } thanks.

---

## [Rspec and should eql](https://www.ruby-forum.com/t/rspec-and-should-eql/211506)

<div class="topic-metadata">

**Author:** [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Replies:** 6\
**Last updated:** [September 6, 2011, 12:57pm UTC](https://www.ruby-forum.com/t/rspec-and-should-eql/211506 "2011-09-06T12:57:31Z")

</div>

Having troubles with rspec and should eql… in a rails 3.1 app spec has this User.first.name.should eql(‘admin’) get this error .rvm/gems/ruby-1.9.2-p290/gems/remarkable-4.0.0.alpha4/lib/remarkable/ core/macros.rb:15…

---

## [Undefined method \`dependent' - rspec and shoulda](https://www.ruby-forum.com/t/undefined-method-dependent-rspec-and-shoulda/211473)

<div class="topic-metadata">

**Author:** [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Replies:** 0\
**Last updated:** [September 5, 2011, 8:42am UTC](https://www.ruby-forum.com/t/undefined-method-dependent-rspec-and-shoulda/211473 "2011-09-05T08:42:16Z")

</div>

hello, Getting this error when using shoulda and rspec for model tests. my gemfile … gem “shoulda-matchers” … spec file … it { should have\_many(:balances).dependent(:destroy) } error: User shoulda validations …

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

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