rspec

Rails: using ZenTest / autospec to test specs in new directories

I am adding a directory for services classes in my rails application: app/services I would like to add specs for these classes in the directory: spec/services I added a spec to spec/services, but running autospec does not run the example. Is there a way to configure autospec to run examples in new directories? Thanks. ...

How to diff multiline strings with RSpec?

I am generating some XML using a builder, and would like to compare the results to some file contents. However, since the strings are so long, the output is hard to read when the strings differ. I know there are a number of libraries for diffing strings in ruby, but is there a built in facility in rspec for generating multiline string ...

cucumber + webrat: checking text appearing twice

I am working on a rails app to self teach BDD and testing in general. Using cucumber + webrat + rspec, after railcasts video tuts. In this app a quiz has_many questions. The view I am testing should render the question twice and non contiguously. (not testing contiguity here) I have a cucumber scenario aimed at checking this Given quiz...

Rspec: "undefined local variable or method `controller_class_path' for #<RspecControllerGenerator"

I keep getting this error when I try to run ./script/generate rspec_controller foo undefined local variable or method `controller_class_path' for <RspecControllerGenerator:0x25b046c> I am using Rails 2.3.3, rspec 1.2.8, rspec-rails 1.2.7.1 The offending line is line 15 in rspec-rails/generators/rspec_controller/rspec_controller_gen...

rspec mock question

I am trying to Mock an object that is being passed into another object, and am having no success. Can someone show me what I am doing wrong? class Fetcher def download return 3 end end class Reports def initialize(fetcher) @fetcher = fetcher end def status @fetcher.download end end describe Reports do before...

Rspec 'should change' with floating point

Is it possible to use RSpec .should(change(...)).by(...) with float numbers and set the compare precision like this: lambda { ...}.should change(unit, :price).by(12.151, 10e-5) Thanks, ...

autospec with cucumber in rails app

I have cucumber features working fine and rspec spec working fine i can run both cucumber features and spec spec and they all work but now im looking at getting autospec to run but running does the produces the following Warning: $KCODE is NONE. /opt/local/lib/ruby/gems/1.8/gems/cucumber-0.3.90/lib/cucumber/step_definition.rb:100: warni...

Using shoulda macros with RSpec

I'm trying to use the shoulda macros within RSpec and am having some problems. I've done the following: spec_helper.rb: require 'shoulda/active_record/macros' Spec::Runner.configure do |config| ... config.include(Shoulda::ActiveRecord::Macros, :type => :model) spec/models/foo_spec.rb: describe Foo do it { should_have_i...

What is the standard/conventional location for a test text file with rspec?

We've inherited an application that uses a script to import data from a text file, but doesn't test the import script. I'd like to write some tests for that script, and will need test text files (these are not fixture files). Where would you normally put those files? A data directory? In the new support directory? ...

How to say "should_receive" more times in RSpec

I have this in my test Project.should_receive(:find).with(@project).and_return(@project) but when object receive that method call two times, I have to do Project.should_receive(:find).with(@project).and_return(@project) Project.should_receive(:find).with(@project).and_return(@project) Is there any way how to say something like Pro...

How do I get spec to look for _spec.rb files in mutiple subdirs?

I got the following my rspec.rake file, yet it doesn't treat ** as it should - iteration through all subdirectories of spec/qa, but instead it only finds relevant files that are one level down. script/runner ./vendor/gems/rspec-1.2.8/bin/spec --options "./spec/qa/spec.opts" ./spec/*/_spec.rb Thank you much, Masha ...

Simulating an XHR GET request

In my RSpec tests, I need to simulate an AJAX GET request to the index action, and have been using the code as described in both the Rails docs and the RSpec book: xhr :get, :index This always fails though, as the test tries to load the show action (without any parameters) rather than the specified index action. The controller action...

Testing Liquid templates in rails using Rspec

looking to use rspec to test liquid templates. Anyone tried this? Is it possible. Specifically our app allows users to submit a set of templates and I'd like to be able to write integration tests to validate these templates. Alternative solutions/approaches welcome.. ...

How can I get the status of rspec execution in "after :all" block?

after :all do browser.close unless rspec_failed? end def rspec_failed? ??? # What should I write here end ...

what are the advantages of mocha over rspec's built in mocking framework?

I notice that a lot of people prefer mocha over rspec's built in mocking framework. Can someone explain the advantages of mocha, or any alternative, over rspec's built in mocking framework? ...

How to make rails autospec stop looping

I'm using autospec and when all tests are passing, the green messages pops up just once, but when the tests are NOT passing, it remains popping up infinite red windows in growl. Does anybody knows how to turn this off and make autospec run just after I save my files? I have a .autotest file in my home with these contents: require 'aut...

How much do you test your controllers?

I am currently beginning with BDD - I have not written any tests before. I always try to keep my models fat and my controllers skinny. What do you think - are controller specs necessary? Best regards ...

What am I doing wrong with this rspec helper test?

Hi there, All I'm trying to do is spec how a one line helper method for a view should behave, but I'm not sure what kind of mock object, (if any) I should be creating if I'm working in Rails. Here's the code for events_helper.rb: module EventsHelper def filter_check_button_path params[:filter].blank? ? '/images/buttons/bt_searc...

Snow Leopard + cucumber/webrat/rspec

Since I've upgraded to snow leopard I've been having tons of problems using cucumber to run my features. Currently, every time I run cucumber I get the following error. Missing these required gems: webrat cucumber >= 0.3.100 webrat >= 0.5.0 rspec >= 1.2.6 rspec-rails >= 1.2.6 You're running: ruby 1.9.1.243 at /...

Ruby 1.9.1 with rspec "can't modify frozen object"

I just updated to Ruby 1.9.1 and nearly all my rspec are broken giving me a "can't modify frozen object". Even the Rspec sample code from a generate rspec_controller fails. RuntimeError in 'DownloadsController should use DownloadsController' can't modify frozen object ...