rspec

How to turn off generators for RSpec 2 in Rails 3?

I installed the current RSpec 2 Beta under Rails 3 RC as mentioned on the GitHub page (and several blogs). Everything works fine, but I am not able to turn off specific generators like advised on some blogs. Here is what I do in ./config/application.rb: config.generators do |g| g.test_framework :rspec, :fixtures => false, :views => f...

autospec can't run tests after touching a file.

I've got two files in app/views/users -rw-r--r-- 1 create.html.erb -rw-r--r--@ 1 new.html.erb With autospec running and all my tests passing, I touch 'new.html.erb' and and growl notifies my that my tests can't run and autospec outputs: 0 examples, 0 failures If I start autospec again all my tests pass. If I touch 'create.html.erb...

How do I stub out the flickraw library in my app's unit tests?

My Rails 2 app displays a slideshow of photos from Flickr via the flickraw library. My code works, but I'm stuck on how to properly write RSpec unit tests. I have a Slide class that encapsulates everything that my app needs from flickraw. It acts somewhat like a model object but doesn't use ActiveRecord. It doesn't do much work; it de...

Testing view helpers in Rails with RSpec

Guys, I need to test the following helper: def display_all_courses @courses = Course.all output = "" for course in @courses do output << content_tag(:li, :id => course.title.gsub(" ", "-").downcase.strip) do concat content_tag(:h1, course.title) concat link_to("Edit", edit_course_path(course)) end end ...

Where I can learn Cucumber in detail?

I am new on Ruby on Rails testing. I have seen many testing tools, such as Rspec,Cucumber,Seleneium,Watier etc. but could not detail information about that. Please give me a link for this. ...

Can I run multiple RSpec/Selenium tests in order without resetting browser state?

So I just started using Steak, which in turn uses Capybara, which in turn uses Selenium. So I've heard it's good RSpec practice to split testing into lots of little it-clauses, each testing a small piece of functionality. But then it makes a test run take a lot longer, because the same steps get repeated for each test. Say I'm testing...

RSpec Argument Error

I'm getting an argument error whenever I run an RSpec test on any controller action that uses a POST or PUT action. It's happening on all of the controllers, no matter what I do. It's just the "wrong number of arguments (1 for 0)" one. The app is working, but the tests are all failing. I think this is happening whenever a "save" is call...

Rails Time inconsistencies with rspec

I'm working with Time in Rails and using the following code to set up the start date and end date of a project: start_date ||= Time.now end_date = start_date + goal_months.months I then clone the object and I'm writing rspec tests to confirm that the attributes match in the copy. The end dates match: original[end_date]: 2011-08-24 ...

Autospec skipping lib/vendor in a Rails project

Hello, I have a rails project which I am testing with rspec using script/autospec and it has been working great. However, I am now trying to add specs for a Vendor module in spec/lib/vendor/*_spec.rb and autospec ignores the files. I have tried adding the following to .autotest based on the answer provided here with no success: Autote...

Writing view_spec for login form with authlogic (rspec2)

Hi there, i am trying to write a view_spec for my login form that uses authlogic. This is my current view_spec: require 'spec_helper' describe "user_sessions/new.html.haml" do before :each do user_session = mock("UserSession").as_null_object assign(:user_session, user_session) end it "should have a login form" do re...

protected "reject" method firing with Rails 3 RC, Mongoid, and Recaptcha and RSpec

Please bear with me as I'm a bit new to rails (especially rails 3), and I'm kinda stumped by this. Basically I want to test my CustomersController in my application using RSpec. When I execute my specs trying to perform a post to the create action in my controller, I get this error, and I'm not sure why: 1) CustomersController as gues...

How do you specify Content-Type (and other headers) and request body in RSpec Rails Controller test?

I'm trying to test a rails action that takes raw json in the POST body. If i curl with the Content-Type: application/json header set, rails parses the params correctly. How do you set the request body and headers directly in an rspec controller test? ...

What's the difference between lambda and begin block?

I am trying to verify if a text have been written to file (build.log) after executing a rake task which will throw an exception. Checkout both the code snippets below, the one with begin works whereas lambda throws a message saying it couldn't find the build.log file. Using begin to test.(works) begin Rake::Task['git:checkout'...

Rails 3 and Factory Girl creating user only if attributes are passed in

Hey, I'm using Rails 3 rc, Factory Girl, and Rspec, and Authlogic. Is there any way or reason why this would happen: When I create a user like this: @user = Factory(:user) I get an issue with password confirmation being "too short". my factories.rb is Factory.define :user do |u| u.username "Test User" u.email "...

rspec not receiving save method

Hello all, I'm very new to rails and I've been following a lot of great tutorials and examples out there in the community, so first off thank you! I'm having a problem with my test code. The application works, and I can see from tailing the test logs that the database is being written, but for some reason, it's not returning the save ...

Rails 3 RSpec 2 NetBeans integration

NetBeans 6.9 provides a custom Runner class for RSpec to be integrated into the IDE. I'm trying to get my Rails 3 applications specs to be correctly displayed inside NetBeans, but RSpec 2 seems no longer to support custom Runner classes in general. Any ideas how to get the specs into the IDE anyway? ...

How do I parameterise RSpec tests so I can test the same behaviour under slightly different conditions

I'm implementing a service that has several different ways it can be accessed: Using simple query parameters With parameters encoded as a Javascript object For some calls both GET and POST are supported, with POST being used when there is large amounts of data being sent to the service. What's the best way to structure my RSpec test...

How to create a RSpec task with Rspec 2?

Using tspec 2 I want to create a rake task on the fly to be run, we used to do the following in RSpec 1: Spec::Rake::SpecTask.new(:client) do |t| t.spec_files = FileList['spec/units/client/**/*_spec.rb'] t.spec_opts = spec_opts end But now Spec::Rake::SpecTask was substituted, any suggestions? Regards ...

RSpec how to stub open?

I've been trying to stub open, the open-uri version, and I'm not succeeding. I've tried doing the following but the request keeps going through: Kernel.should_receive(:open).and_return("Whatever for now") I've also tried to do OpenURI::OpenRead.should_receive(:open).and_return("Whatever for now") Since I tracked down that was wher...

Rspec Rails mocking associated model not working after find()

I have some nested models that require a bit more than the standard accepts_nested_attributes_for logic. Instead of automatically creating or updating child records based on id key, in this case the child records must already exist and have certain other conditions, or it raises an error. So as part of this, I have a parent model itera...