rspec

rails image_submit_tag with cucumber/webrat

I've the following search form with image_submit_tag instead of submit_tag. Now I get the obvious fail when cucumber runs: When I fill in "q" with "sachin" # features/step_definitions/web_steps.rb:33 And I press "submit" # features/s...

Facing problem with running configuring environment for cucumber / rspec on ubuntu

I'm trying a basic RSpec / Cucumber tutorial given here However, when I run the command "script/cucumber features", I get the following error and am not able to proceed further. Using the default profile... uninitialized constant Spec::Example (NameError) /home/badal/NetBeansProjects/blog/vendor/rails/activesupport/lib/active_support/d...

Rails: When testing controllers with RSpec, how do I stop them from redirecting?

I have controller methods that look like this: class TestController < ApplicationController def testAction render :json => { 'success'=>1 }.to_json end end When I load this action in the browser, I get what I expect: {"success":1} When testing with RSpec, however, response.body gives me '<html><body>You are being <a href="htt...

Ruby on Rails Rspec migrates database when running rake spec:plugins

I'm trying to test a plugin that i wrote by running: rake spec:plugins When i execute this command it appears that it drops my database tables (in my test DB) and then runs a migration without any plugins loaded to give me a clean database. This would normally be fine, but I am using a plugin that allows me to set index length limits ...

Error after second spec run with rspec and autospec

After installing rspec/ZenTest and running autospec, it runs my specs the first time as expected. After making a change to one of my specs and upon running the second time I get the following results: /usr/bin/ruby1.8 /usr/lib/ruby/gems/1.8/gems/rspec-1.3.0/bin/spec --autospec /home/schambers/Projects/notebook/spec/models/user_spec.rb -...

Mocking ActiveRecord relationship beheavior in RSpec tests

I've run into this problem with testing. Let's assume I have two models, User and Post, where user has_many :posts. I'm trying to spec out a code block that includes something like this: user = User.find(123) post = user.posts.find(456) I know how to mock out the User.find and user.posts parts. The user.posts mock returns an array of...

Rspec: Is there a problem with rspec-rails when initializing a controller class with super(args)?

Hi there, I've been using Rspec for a while and for some reason am receiving errors on a controller called ReferencesController. The error says that I have to specify the controller name by either using: describe MyController do or describe 'aoeuaoeu' do controller_name :my I've tried both variations: describe ReferencesC...

rspec testing a controller post changing my params from symbols to strings and breaking my tests

In my controller spec I am doing this: it "should create new message" do Client.should_receive(:create).with({:title => 'Mr'}) post 'create' , :client => {:title => "Mr" } end ... and in my controller I am doing ... def create client = Client.create(params[:client]) end However this is failing with the following error message...

Structuring RSpec file structure and code for tests with very large coverage?

I've just started looking at a project that has >20k unit tests written in Rspec (the project itself isn't written in Ruby; just the test cases). The current number of test cases is expected to grow dramatically in the future, as more functionality is added. What's already happened (over an extended period) is that RSpec started out be...

Why would using File.open call once result in it being called 3 times according to rspec

Below you can see that I'm calling File.open only once but rspec is telling me it received it 3 times. def self.import_file(filename) current_file = filename.split('/').last destroy_all(["filename = ?",current_file]) unpack_format = "A#{INPUT_FILE_FORMAT.map{|element| element[1]}.join("A")}" debugger File.open(filename, 'r')....

RSpec can't find Cucumber gem

When running rspec I get the following error: no such file to load -- cucumber-rails /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:158:in `requi...

Cucumber/RSpec testing of improbable errors

I've got a problem testing the following controller code: def publish if @article.publish flash[:notice] = "Article '#{@article.title}' was published." else # This is not tested flash[:error] = "Error publishing article." end redirect_to :action => :index end Where the function publish looks like that: def publish...

Does spec tests migrate dbs on every test?

I did rake test:prepare and clone the db. Then when I do spec spec/controllers/file, it migrates the db every single time. Is that supposed to do that? I thought it was only supposed to migrate the dbs once. Thanks ...

Rack rSpec Controller Tests with Rack Middleware issue

Howdy, I'm having big trouble testing with rSpec's controller API. Right now I'm using a middleware authentication solution (Warden), and when I run the specs, the proxy added by the middleware is not there, and all the authentication tests are throwing NilPointerExceptions all over the place. It seems rSpec is not adding the middlewar...

How can I mock/fake the existence of a file using rspec?

This is what I have: it "should be able to get a valid directory path" do @asset.some_file_path.should == "/something/test.jpg" end The problem is that some_file_path returns "/not_here_yet.jpg" if there is no existing file. def some_file_path if File.exists(self.my_image_path) return my_image_path else return "/not_...

Mocking an object method within a Thread?

In the situation below the @crawl object DOES RECEIVE the crawl call, but the method mock fails ie: the method is not mocked. Does Thread somehow create its own copy of the @crawl object escaping the mock? @crawl.should_receive(:crawl).with(an_instance_of(String)).twice.and_return(nil) threads = @crawl.create_threads thread crea...

Why am I getting undefined method errors for "strip" and "downcase" when I run RSpec on my models?

I am running an RSpec test on a model and getting errors for string methods such as: "index, "downcase," and "strip." Any ideas why that is and how I can fix it? ...

Unit testing paperclip uploads with Rspec (Rails)

Total Rspec noob here. Writing my first tests tonight. I've got a model called Image. Using paperclip I attach a file called photo. Standard stuff. I've run the paperclip generator and everything works fine in production and test modes. Now I have a spec file called image.rb and it looks like this (it was created by ryanb's nif...

How to run arbitrary object method from string in ruby?

So I'm fairly new to ruby in general, and I'm writing some rspec test cases for an object I am creating. Lots of the test cases are fairly basic and I just want to ensure that values are being populated and returned properly. I'm wondering if there is a way for me to do this with a looping construct. Instead of having to have an asser...

how to add to rspec-rails callbacks

I have some code that adds to the callbacks that rspec-rails adds by default to setup and teardown fixtures. My code looks something like: module Test module Unit class TestCase append_before(:each) do Test::Unit::AfterFixturesLoaded.custom_stuff1 end append_after(:each) do Test::Unit::AfterFixt...