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
2
votes
2 answers

Get HTTP response Using Shoulda Ruby on Rails

I'm migrating over to shoulda from rspec and I can't seem to get access to the http response. Can someone point out what I may be doing wrong? context "doing somethin" do setup do get :index end @response.body …
Schneems
  • 14,918
  • 9
  • 57
  • 84
2
votes
1 answer

How to use shoulda-matchers with Minitest Specs style in Rails?

The shoulda-matchers documentation for Minitest usage provide an example for how to use them in the assertion style, like so: class PersonTest < ActiveSupport::TestCase should validate_presence_of(:name) end But how do I use them using the…
user1647525
  • 311
  • 3
  • 14
2
votes
3 answers

Is it better to use shoulda-matchers or Factory Girl in unit testing Rails models?

I'm practicing testing (just got into it), and am wondering whether it's better to use shoulda-matchers or Factory Girl - or a combination of both - in testing models. For example, I currently just use the simple shoulda-matchers test, which is nice…
fibono
  • 773
  • 2
  • 10
  • 23
2
votes
1 answer

Shoulda Matchers attempting to insert `nil` value while validating uniqueness

I have Referral model that tracks referrals (i.e. think when a user on a social media site generates a unique referral/invite link and invites others to join the app). Referrer - one who sends out their unique invite link Referree - one who…
user2490003
  • 10,706
  • 17
  • 79
  • 155
2
votes
2 answers

undefined method define_enum_for for RSpec::ExampleGroups

I am getting undefined define_enum_for method error after upgrading rails to 4.2.0 from 4.1. Is there any fix for this? Rails : 4.2.0 Ruby : ruby 2.1.5p273 (2014-11-13 revision 48405) [i686-linux] 1) Recording Failure/Error: should…
Raghvendra Parashar
  • 3,883
  • 1
  • 23
  • 36
2
votes
1 answer

Rails 4/ validations - numericality: { only_integer: true } necessary on 'integer' attribute?

I had this on my models: validates :deal_sector_id, presence: true, numericality: { only_integer: true } deal_sector_id is a integer postgresql column. I'm starting to doubt that numericality: { only_integer: true } is…
Mathieu
  • 4,587
  • 11
  • 57
  • 112
2
votes
1 answer

Current trend in testing models in a rails3 + datamapper application

What is the current trend for testing models in a Rails3+DataMapper application. I want to use RSpec but sorely miss the concise testing provided by shoulda macros. Question - Is there a way of getting the best of both worlds, ie. a nice dsl for…
Akshay Rawat
  • 4,714
  • 5
  • 40
  • 65
2
votes
1 answer

validate_presence_of shoulda spec and default values

I have some code in a Rails model that does this: has_one :plan validates_presence_of :plan And used to do this: after_initialize :set_plan def set_plan self.plan ||= FreePlan.new end and now does: def plan super || (self.plan =…
David N. Welton
  • 1,875
  • 18
  • 33
2
votes
3 answers

Allow blank on should validate_uniqueness_of

Using shoulda, any ideas how to allow blank when having this test: should validate_uniqueness_of(:email) Thanks.
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
2
votes
1 answer

Shoulda route matcher with subdomains

I am using shoulda matchers to test critical routes on Rails 4.2.1 with Ruby 2.2.0 on a new application. I just moved my API namespace to a subdomain, and I can't figure out how to get the shoulda routes matcher (or any other concise routes test) to…
Lee
  • 686
  • 1
  • 10
  • 23
2
votes
7 answers

Shoulda_matches error: undefined method `validate_presence_of' for #

I am learning TDD and trying to use shoulda_matchers to help with my testing but I get a very strange error. Here is my test: spec/models/idea_spec.rb require 'rails_helper' describe Idea do context 'Validations' do describe 'title' do …
MandyM
  • 87
  • 3
  • 11
2
votes
1 answer

Shoulda-matchers throwing confusing errors

I'm having problems with what I think is the shoulda-matchers gem after updating it from v1.4.2 to v2.7.0, and the failures differ depending on how I run the tests. When I run the current test suite 'normally', I get failures like…
Arepo
  • 825
  • 1
  • 9
  • 23
2
votes
1 answer

Creating a shoulda matcher for links in view specs

I could be barking up the wrong tree here, but I'm trying to build a shoulda matcher for rails view specs. Right now I have a view spec that looks something like this: require 'rails_helper' RSpec.describe 'layouts/_navigation', :type => :view do …
Daniel Hollands
  • 6,281
  • 4
  • 24
  • 42
2
votes
2 answers

How to create contexts in shoulda macros

Asking this question again with smaller code sample: # this is a dummy shoulda macro that creates a context def self.macro_context context "macro" do yield end end # i am expecting this test to fail within the macro context …
Honza
  • 4,349
  • 2
  • 24
  • 40
2
votes
1 answer

how to verify length and numericality of an atribute in rails with Rspec

I have a customer model with a first name, last name, and phone number. I want to let the user enter in the phone number in any format such as 555-555-5555 or (555)555-5555 or 555.555.5555 Here is my Customer model class Customer <…
Doug Steinberg
  • 1,122
  • 14
  • 32