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
10
votes
5 answers

How can I mute Rails 3 deprecation warnings selectively?

I am upgrading a Rails 2 to Rails 3 application (code not written by me). The (well tested code) uses shoulda and Test::Unit, and extensively uses the macros should_create and should_change. I understand from this discussion that the shoulda…
9
votes
3 answers

Shoulda validate_format_of . not_with has problem in framework (or in my understanding)

I put the following code into an RSpec test: it { should validate_format_of(:email).not_with('test@test')} and setup the actual class with: validates :email, :presence => true, :format => /\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i And when I…
user426623
  • 91
  • 1
  • 3
9
votes
1 answer

Shoulda rspec matchers :on => :create

I am using some of the Shoulda rspec matchers to the test my model, one of them being: describe Issue do it { should_not allow_value("test").for(:priority) } end My problem with this is that my validation in my model looks like…
trobrock
  • 46,549
  • 11
  • 40
  • 46
9
votes
2 answers

how to test rspec shoulda for custom validation in rails?

I have a Private methods in my model like the following: validate :record_uniq private def record_uniq if record_already_exists? errors.add(:base, "already exists") end end def record_already_exists? question_id =…
Sri
  • 2,233
  • 4
  • 31
  • 55
8
votes
3 answers

no such file to load -- rspec/matchers - rspec-rails, shoulda, cucumber, factory girl, Rails2.3.10

I've inherited an old Rails2.3 app. It's very complex and has (shock, horror) no tests whatsoever. I'm used to rspec and cucumber so I thought I'd start working on getting specs and features defined for the eventual (long-away) upgrade to Rails 3.…
Matt Rogish
  • 24,435
  • 11
  • 76
  • 92
8
votes
2 answers

rspec and shoulda - complementary or alternatives?

I've used shoulda for a while, and I've read and played with rspec. I have not done an in depth compare and contrast. But it seems to me like there is some overlap between the two, but that they are not 1-1 replacements. I am considering writing…
pitosalas
  • 10,286
  • 12
  • 72
  • 120
8
votes
1 answer

Shoulda-Matchers and Custom Error Messages

I am trying to do some basic rspec testing with shoulda matchers and I've come upon an error I haven't seen asked on SO before. I have a unique attribute called name, but for reasons required of the project I have overwritten the default "has…
MageeWorld
  • 402
  • 4
  • 14
7
votes
2 answers

Testing uniqueness in a scope in a Rails project using shoulda (but not rspec)

I have a user class with an email that is unique but scoped to the tenant: class User < ActiveRecord::Base validates :email, :uniqueness => {:scope => :tenant_id, :allow_blank => true} #... end I'm trying to test it with: class UserTest <…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
7
votes
2 answers

Shoulda vs Remarkable for rspec and rails

I'm using rspec and cucumber for BBD. Now I'm migrating to rails 3 and rspec 2 and as I could see both of frameworks (shoulda and remarkable) support rails 3 and rspec 2. I have never used shoulda or remarkable. What should I prefer to use with…
petRUShka
  • 9,812
  • 12
  • 61
  • 95
7
votes
8 answers

BDD on Rails - Is the community more behind Shoulda or RSpec?

For a new application I want to start dabbling in BDD and I'm trying to decide between using RSpec or Thoughtbot's Shoulda. I like the macros that Shoulda uses, and the fact that it doesn't seem to reinvent the way Ruby/Rails does testing, but…
Wayne Molina
  • 19,158
  • 26
  • 98
  • 163
6
votes
3 answers

How to Unit Test namespaced models

In my Rails app, I make heavy use of subdirectories of the model directory and hence of namespaced models - that is, I have the following directory heirarchy: models | +- base_game | | | +- foo.rb (defines class BaseGame::Foo) | +- expansion | …
Chowlett
  • 45,935
  • 20
  • 116
  • 150
6
votes
2 answers

Is there a good way to test `before_validation` callbacks with an `:on` argument in Rails?

I have a before_validation :do_something, :on => :create in one of my models. I want to test that this happens, and doesn't happen on :save. Is there a succinct way to test this (using Rails 3, Mocha and Shoulda), without doing something…
nfm
  • 19,689
  • 15
  • 60
  • 90
6
votes
3 answers

rake not running unit tests

I've upgraded my app from using config.gem to a Gemfile with bundler and have noticed that my unit tests have now stopped running. It's a bit strange and I'm not entirely sure where to start looking. When I run rake test:units --trace I can see my…
jonnii
  • 28,019
  • 8
  • 80
  • 108
6
votes
1 answer

Shoulda matchers have_many with custom relation name

How do I test this ActiveRecord relation using shoulda matchers? Models class User < ActiveRecord::Base has_many :articles end class Article < ActiveRecord::Base belongs_to :author, class_name: 'User' end Test describe User do it { should…
Igor Pantović
  • 9,107
  • 2
  • 30
  • 43
6
votes
4 answers

Shoulda: Test validates_presence_of :on => :update

I'm using Shoulda in combination with Test::Unit on one of the projects I work on. The issue I'm running into is that I recently changed this: class MyModel < ActiveRecord::Base validates_presence_of :attribute_one, :attribute_two end to…
jerhinesmith
  • 15,214
  • 17
  • 62
  • 89
1 2
3
25 26