Questions tagged [shoulda]

Shoulda, developed by thoughtbot, provides constructs for organizing Test::Unit tests and matchers for testing Ruby on Rails applications that work with Test::Unit or RSpec.

Shoulda organizes Test::Unit tests into a collection of nested contexts with support for setup and teardown blocks and should clauses. Shoulda also provides matchers for testing Ruby on Rails applications that work with Test::Unit, Minitest or RSpec.

Along with shoulda, thoughtbot provides many many other community libraries.


Resources


Related tags

383 questions
16
votes
2 answers

Rspec, shoulda and spork does not work together

when I run rspec spec/models result is OK. But when I use spork, every test where shoulda macros (like it { should validate_presence_of(:title) } is used FAILS with error like: undefined method 'validate_presence_of' for ... I use: rails…
boblin
  • 3,541
  • 4
  • 25
  • 29
16
votes
13 answers

Setup Factory Girl with Test::Unit and Shoulda

I'm trying to set up Factory Girl with Test::Unit and Shoulda in Ruby on Rails. I have installed the gem, created my factory file under the test/factories directory, and created my spec file under the test/models directory. The current error I'm…
NolanDC
  • 1,041
  • 2
  • 12
  • 35
15
votes
6 answers

Rspec, shoulda, validate_uniqueness_of with scope and wrong error message

I have following Rspec test: describe Productlimit do before(:each) do @productlimit = Factory.create(:productlimit, :user => Factory.create(:user)) end subject { @productlimit } ... it { should…
BvuRVKyUVlViVIc7
  • 11,641
  • 9
  • 59
  • 111
15
votes
4 answers

In Rails controller tests, Is there a way to simulate a specific remote IP?

Some functionality in my app works differently depending on the client's IP address. Is there a way to test that in Rails functional tests? I'm using Test::Unit and Shoulda.
Ethan
  • 57,819
  • 63
  • 187
  • 237
14
votes
3 answers

RSpec vs. Shoulda?

I am new to the unit testing scene; I have only been using unit tests for about 2 months now. When I unit test in Ruby I currently follow the TDD style and use Test::Unit::TestCase. I have also read about RSpec and how it follows the BDD…
ab217
  • 16,900
  • 25
  • 74
  • 92
14
votes
2 answers

Testing devise with shoulda

I'm having some difficulties in testing devise with shoulda: 2) Error: test: handle :index logged as admin should redirect to Daily page. (Admin::DailyClosesControllerTest): NoMethodError: undefined method `env' for nil:NilClass devise (1.0.6) [v]…
morgan freeman
  • 6,041
  • 3
  • 25
  • 32
13
votes
1 answer

Paperclip/Rspec tests: Is there a faster way to test paperclip validates_attachment_content_type?

One thing I've noticed is that in most of the projects I do, the one spec that always takes a long time (30 seconds +) is this shoulda/paperclip helper: it { should validate_attachment_content_type(:bannerimage) .allowing('image/png',…
PlankTon
  • 12,443
  • 16
  • 84
  • 153
13
votes
2 answers

How do I compare two text files with RSpec?

I have a method which compares if two text files have the same content. How do I compare if two text files have the same content using RSpec?
user1830961
12
votes
2 answers

Error when checking enum value with shoulda-matchers

In my device model, I have enum device_type: { ios: 1 , android: 2 } validates :device_type, presence: true, inclusion: { in: device_types.keys } And in my device_spec.rb, I write some tests for this like describe 'validations' do subject {…
Van Huy
  • 1,607
  • 1
  • 13
  • 16
12
votes
1 answer

ActiveSupport::TestCase vs Test::Unit::TestCase when unit testing rails

I recently noticed my test database is not being cleaned up after my tests run if my tests subclass Test::Unit::TestCase. If my tests subclass ActiveSupport::TestCase, everything is cleaned up properly. Can anyone explain why, and/or provide an…
Lee
  • 9,432
  • 3
  • 30
  • 34
12
votes
4 answers

shoulda matchers should validate_uniqueness_of failing with scope

I have 3 models, user, game, and player. There's basically a many to many relationship between users and games, with players as the join table, except players have other info so it has its own model. A player needs a unique combo of game id and user…
bdwain
  • 1,665
  • 16
  • 35
11
votes
2 answers

How do I test for a 204 response in RSpec in Rails?

I am testing the delete action of my resource controller as follows: describe ResourceController do context "DELETE destroy" do before :each do delete :destroy, id: @resource.id end it { should respond_with(:no_content) } …
Coffee Bite
  • 4,956
  • 5
  • 33
  • 38
11
votes
3 answers

Is shoulda destroying my backtraces?

I have a test more or less like this: class FormDefinitionTest < ActiveSupport::TestCase context "a form_definition" do setup do @definition = SeedData.form_definition # ... I've purposely added a raise "blah" somewhere down the…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
11
votes
2 answers

Rspec should change count without lambda

I am trying to figure out another way of writing the should change count test (without lambda). I am using Rails 3. I am also utilizing the shoulda matcher gem Reason - All test cases are in the format describe "some stuff" do it { should ... } …
athap
  • 1,657
  • 1
  • 12
  • 9
11
votes
5 answers

Using shoulda to refactor rspec tests on Rails models

After learning about shoulda-matchers by answering another StackOverflow question on attribute accessibility tests (and thinking they were pretty awesome), I decided to try refactoring the model tests I did in The Rails Tutorial in an attempt to…
Paul Fioravanti
  • 16,423
  • 7
  • 71
  • 122
1
2
3
25 26