rspec

Controller specs in isolation mode and render :update

Hi folks, I am using RSpec for writing my controller tests/specs. I faced the problem, that the following code gets rendered: render :update do |page| page['middle_content'].replace_html :partial => "admin/pages/show" end Isolation mode is the default, isn't it? How can I fix this or am I doing something wrong? Here is for examp...

Silencing Factory Girl logging

Just to clear the air, I am not some cruel factory master trying to silence working ladies. I am having a very annoying problem where when using Thoughtbot's factory girl in my specs, every time Factory.create(:foo) is used, the newly created ActiveRecord model instance is logged to the console. This makes looking at my console output ...

Why are my Cucumber tests keeping the MySQL connection alive after each scenario?

I was having a really odd problem in my cucumber tests that was causing scenarios that were passing individually, to fail when run with others in a feature. I deduced this was a MySQL related issue and sure enough, a co-worker came along and recommended I change my connection pool to a higher value in my database config. Lo' and behold, ...

Why won't ruby-debug allow me to see local variables in my specs?

I am trying to use ruby-debug to debug my specs. When i do this, i am not able to access local variables. Instance variables, however, are fine. Is there a way to make this work with local variables? Here is an example spec: require 'spec/autorun' describe "empty spec" do it "should be able to be debugged" do x = 'foo' @x = '...

How to use rspec to test named routes?

Hi there, Given I have a named route: map.some_route '/some_routes/:id', :controller => 'some', :action => 'other' How do I use the routing spec file 'spec/routing/some_routing_spec.rb' to test for that named route? I've tried this after the "describe SomeRouteController" block and it doesn't work, I get 'undefined method "helper": ...

RSpec in Rails: How to skip a before_filter?

Hello everyone, I am trying to test my controller and maintain separation of concerns. The first concern is "Who is able to execute which action?" I am using authlogic for authentication and be9's acl9 for authorization. But this should not matter, all my authorization concerns are handled in a before_filter. I am testing such a befor...

How to fix a spec for stripping hml tags after adding javascript to a view in Rails?

Working on a request to add a pretty tooltip to a page (using jQuery tooltip plugin, as recommended by others on my team). Pretty tooltip is working fine, but two of the existing specs now fail, an example below: describe 'with a discussion post containing html' do before(:each) do @post.update_attributes(:body => "some <strong>...

RSpec setup for an application that depends on an external database from another application.

I've had to add features to an application that depends on a database from another application. I've been able to set up a connection to this external database and pull data from it. However, I'm not sure how to get my main application to create a test database for this external application. It would be awesome if there some way to pul...

RSpec: Expecting a message multiple times but with differing parameters

I currently have some expectations set up on a mock with consecutive calls: The spec: @my_mock = mock("a_mock") @options1 = {:some => "option"} @options2 = {:some_other => "option"} @first_param = mock("first_param") @my_mock.should_receive(:a_message).with(@first_param, @options1) @my_mock.should_receive(:a_message).with(@first_param...

Guidance on testing extremely long form with 20+ required fields, using Rspec / Cucumber

Hi all, Just wanted to get some opinions on how to go about testing an extremely long form with 20+ required fields. It seems like my Cucumber scenario could be like 25 lines long if I tried to describe every field that need to be filled in (something like "And I fill in "Name:" with blah, And I fill in "Address" with foo, etc.). If I ...

RSpec View testing: How to modify params?

I am trying to test my views with RSpec. The particular view that is causing me troubles changes its appearance depending on a url parameter: link_to "sort>name", model_path(:sort_by => 'name') which results in http://mydomain/model?sort_by=name My view then uses this parameter like that: <% if params[:sort_by] == 'name' %> <div>Sorte...

How do I silence the following RightAWS messages when running tests

I'm using the RighAWS gem, and mocking at the http level so that the RightAWS code is being executed as part of my tests. When this happens I get the following output ....New RightAws::S3Interface using per_request-connection mode Opening new HTTP connection to s3.amazonaws.com:80 .New RightAws::S3Interface using per_request-connecti...

How thorough should you get with RSpec testing?

I'm just starting to grasp BDD and RSpec and one thing I'm really having trouble with is figuring out how thorough I should be with my testing. I'm just not understanding how fine-grained my testing should be to still be useful but not double development time. Is it just a matter of preference? Or is there some general standard for wha...

Should I mock my model in rails controller tests?

I am finding holes in my coverage because I have been mocking my models in controller examples. When I remove a model's method upon which a controller depends, I do not get a failure. Coming from TDD in statically typed languages, I would always mock dependencies to the object under test that hit the database to increase speed. I would...

How do I globally configure RSpec to keep the '--color' and '--format specdoc' options turned on

How do I set global configuration for RSpec in Ubuntu. Specifically so, --color and --format specdoc stay turned on, across all my projects (ie every time I run rspec anywhere). ...

Selenium screenshots using rspec

I am trying to capture screenshots on test failure using selenium-client and rspec. I run this command: $ spec my_spec.rb \ --require 'rubygems,selenium/rspec/reporting/selenium_test_report_formatter' \ --format=Selenium::RSpec::SeleniumTestReportFormatter:./report.html It creates the report correctly when everything passes, since no...

Why can't my Rails app find the gems that are packaged with it?

I've got a Rails app making use of Cucumber and RSpec. We are storing the gems under vendor/gems and trying to get the app building (running tests) in a CI server. When I try to run our tests I'm getting the following error: Missing these required gems: cucumber >= 0.3.11 rspec-rails >= 1.2.6 When I run RAILS_ENV=test rake gems...

Reddit clone in Rails with Rspec, resource_controller problem

http://github.com/samliu/rlinkset ^^ My code so far is pushed to there. Essentially, I'm using resource_controller and I don't really understand resource_controller. When I used scaffolding to create my Post model, I gave it fields like :integer parent #to say what level a post is at (which post ID is this post's parent) :integer user...

How could avoid the rspec drops the test database?

I have some fake data in the test database, but when I run rake spec the script drops and creates the whole database. How could I avoid that? or is it something I'm doing wrong? EDIT: I just don't want to generate 1.000.000 records from the database every time. It took so long. ...

Stubbing a controller method with Sinatra and rspec

Hi all, So I'm trying to figure out a way of stubbing a controller method in rspec for a Sinatra app. The main reason for this is to test the logical flow of the application and to make sure it calls the necessary functions when certain conditions are met. So, in essence, I want to be able to do something like controller.should_receive...