56
votes
10answers
8k views

Speeding up RSpec tests in a large Rails application

I have a Rails application with over 2,000 examples in my RSpec tests. Needless to say, it's a large application and there's a lot to be tested. Running these tests at this point is very inefficient ...
55
votes
13answers
7k views

What's the best way to unit test protected & private methods in Ruby?

What's the best way to unit test protected and private methods in Ruby, using the standard Ruby Test::Unit framework? I'm sure somebody will pipe up and dogmatically assert that "you should only unit ...
39
votes
5answers
10k views

Testing modules in rspec

What are the best practices on testing modules in rspec? I have some modules that get included in few models and for now I simply have duplicate tests for each model (with few differences). Is there a ...
32
votes
11answers
6k views

Ruby unit testing: how to fake Time.now?

What's the best way to set Time.now for the purpose of testing time-sensitive methods in a Unit test? Thanks!
31
votes
8answers
10k views

Why should I use RSpec or shoulda with Rails?

I am setting up a rails app and I just finished making some unit tests and my friend said that apparently fixtures are no longer cool and people are now using RSpec or shoulda. I was wondering what ...
28
votes
2answers
8k views

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 ...
24
votes
10answers
749 views

Catching typos in scripting languages

If your scripting language of choice doesn't have something like Perl's strict mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way ...
22
votes
9answers
9k views

Using factory_girl in Rails with associations that have unique constraints. Getting duplicate errors

I'm working with a Rails 2.2 project working to update it. I'm replacing existing fixtures with factories (using factory_girl) and have had some issues. The problem is with models that represent ...
22
votes
4answers
5k views

Rails: How do I write tests for a ruby module?

I would like to know how to write unit tests for a module that is mixed into a couple of classes but don't quite know how to go about it: Do I test the instance methods by writing tests in one of ...
21
votes
3answers
1k views

Testing: how to focus on behavior instead of implementation without losing speed?

It seems, that there are two totally different approaches to testing, and I would like to cite both of them. The thing is, that those opinions were stated 5 years ago (2007), and I am interested, ...
17
votes
3answers
14k views

RSpec Mock Object Example

I am new to mock objects, and I am trying to learn how to use them in RSpec. Can someone please post an example (a hello RSpec Mock object world type example), or a link (or any other reference) on ...
17
votes
3answers
6k views

Populating an association with children in factory_girl

I have a model Foo that has_many 'Bar'. I have a factory_girl factory for each of these objects. The factory for Bar has an association to Foo; it will instantiate a Foo when it creates the Bar. I'd ...
17
votes
1answer
3k views

How can I get Factory Girl to NEVER hit the database if I am calling Factory.build in order to make my controller tests FAST?

I am on a quest to make my Rails tests faster. I only have 520 tests, but they take 62 seconds to run in bash, and 82 seconds to run in Rubymine. As an example of a typical controller test, I was ...
16
votes
4answers
7k views

has_many while respecting build strategy in factory_girl

Situation # Models class User < ActiveRecord::Base has_many :items end class Items < ActiveRecord::Base belongs_to :user validates_presence_of :user_id end # Factories ...
15
votes
2answers
5k views

unit test in rails - model with paperclip

I'm trying to write a test for a model with a picture, using paperclip. I'm using the test framework default, no shoulda or rspec. In this context, how should I test it? Should I really upload a file? ...

1 2 3 4 5 32
15 30 50 per page