rspec

How can I have autospec/test not run the full test suite after everything goes green?

Same question as waloeiii in twitter: How can I have autospec/test not run the full test suite after everything goes green? The next test I write will be red! I'd rather run the full test suite manually. By the way, I tried adding a failing spec: it "should flunk" do flunk end but autospec seems to ignore it when it fee...

RSpec controller testing - blank response.body

I am stuck with a problem when testing my controllers with RSpec - the response.body call always returns an empty string. In browser everything renders correctly, and cucumber feature tests seem to get it right, but RSpec fails each and every time. Other expectations on the response object, such as response.should render_template('index...

How do you develop outside-in Rails app using Cucumber & RSpec?

I just get started using BDD in Rails application, but I'm not sure what are best practices and workflows? And what other things that I really need for testing for my project such as step definitions, controllers, models, and views? Do I need to test all of those? ...

How do I get rspec / autotest going on a rails project?

What's the best practice for getting RSpec / Autotest going on a Rails project? I googled some stuff but it feels like it may be out of date. ...

ActiveRecord dependency with Ruby, Rails, Cucumber, & RSpec

We are writing a Rails application that is using CouchDB as its data store. We're BDD/TDD'ing with RSpec and Cucumber, which is using WebRat for webpage testing I'm trying to remove ActiveRecord as one of the resources that is being loaded by rails but its causing the cucumber tests to fail. I've removed all references that I can find...

Rails: RSpec controller test passes without action being implemented, why?

I have the following RSpec example which is passing: describe UsersController do it "should render new template on new action" do get :new response.should render_template("users/new") end end The problem is I have not implemented the 'new' action on the UsersController. Can anyone tell me why this test is passing? I am ne...

Rails: problem setting expectations on mock model in RSpec

I am trying to set expectations on a mocked ActiveRecord model. I have created the following example, which should pass based on the documentation I can find. it "should pass given the correct expectations" do payment = mock_model(Payment) payment.should_receive(:membership_id).with(12) payment.membership_id = 12 end It is faili...

RoR and RSpec: How to access controller instance variables without defining accessors?

I'm writing a rspec tests for my controller and i cannot find solution following problem. For one of the edge case tests I need to verify the value of one instance variable. How can i access it without having to define the accessor? By default the usual: controller.variable.should == '3.15' doesn't work. Defining attr_reader :...

RSpec: stubbing Kernel::sleep ?

Is there a way to stub Kernel.sleep in an rspec scenario? ...

Open source Rails projects with great RSpec usage

For learning purposes, I'm looking for open source Rails projects that exemplify idiomatic usage of RSpec for BDD. I can find projects, but I'm not experienced enough with Rails or RSpec to know whether what I'm looking at represents best practices. Thanks! ...

Is there a consensus about test frameworks for Ruby 1.9.x?

A two-parter with a quick intro. Intro: I'm coming to Ruby from Perl, and I'm a bit lost among the test framework choices. I understand that there is probably no single, all-around best choice, but I can't even get a clear picture of the playing field. So, first, MiniTest or Test::Unit? I just realized that 1.9.1 defaults to MiniTest no...

Immutable Active Record Relationships and Attributes (Setters)

I set out to solve a problem we have, where under certain circumstances; we may need to make an attribute or relationship immutable, that is once the attribute is written it is written forever. attr_readonly wasn't appropriate, as that didn't work for relationships, so I tried to prove the concept here: http://pastie.org/562329 This sh...

What is a good Code to Test Ratio?

I am using RSpec for writing tests. What do you think, is a good Code to Test Ratio? ...

Random "%2F" in spec for verifying existence of a comment form.

I am trying to write specs for the posts/show.html.erb view of a simple application I'm putting together to learn rspec. I'm a bit stumped at the moment on trying to figure out where the extra "%2F" is coming from. Any ideas? My spec... it "should render a form to add a comment" do render "posts/show.html.erb" response.shou...

How do I setup model associations in an RSpec test?

I've pastied the specs I've written for the posts/show.html.erb view in an application I'm writing as a means to learn RSpec. I am still learning about mocks and stubbing. This question is specific to the "should list all related comments" spec. What I want is to test that the show view displays a post's comments. But what I'm not ...

Testing authenticated file uploads in merb

This is something that has been driving me mad over the past few days. I have an action which allows authenticated users to upload assets to the site. I know that the controller action is correct as I can run through the process manually however I want to test it using rspec. I have to use the request helper so I can reuse an authentica...

What is the difference between mock and mock_model in RSpec

I've recently came across different tutorials, where people use both mock and mock_model functions. In RSpec tutorial for controllers they use the mock_model function, but right in the documentation of RSpec, there is only mock function, but no mock_model I tried to run some tests myself, and I didn't find any real difference, since ev...

Session variables with Cucumber Stories

I am working on some Cucumber stories for a 'sign up' application which has a number of steps. Rather then writing a Huuuuuuuge story to cover all the steps at once, which would be bad, I'd rather work through each action in the controller like a regular user. My problem here is that I am storing the account ID which is created in the f...

How to test association extension logic in rails with minimal DB overhead.

I am a fan of using mocks and stubs everywhere I can to keep my specs running quickly. I'm kind of stumped as to how I might do this to test the find_special method in the following: has_many :foos do def find_special if proxy_owner.baz ... find stuff else ... find other stuff end end end ...

How to test AJAX request with Merb and Webrat?

I am using merb with rspec and webrat. How to ensure that rjs template was successfully rendered? I cannot just write have_xpath because of ajax. ...