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
3
votes
1 answer

UrlGenerationError when running RSpec Test

I'm trying to run a test that ensures my show template is rendered for a restaurant. After running the test I get: 1) RestaurantsController GET #show Failure/Error: before { get :show } ActionController::UrlGenerationError: No…
Carl Edwards
  • 13,826
  • 11
  • 57
  • 119
3
votes
3 answers

Rails 4 - unit test failing to create model object

I want to unit test an application using shoulda. In the test i'm doing User.create!(name: "James") When i run the test i'm getting the following error: ActiveRecord::StatementInvalid: Mysql2::Error: Field 'name' doesn't have a default value:…
3
votes
2 answers

Shoulda and before_ callbacks

I have simple model: class Category < ActiveRecord::Base belongs_to :board validates :name, presence: true, uniqueness: {scope: :board_id} validates :board, presence: true validates :display_order, presence: true, uniqueness: {scope:…
Marcin Doliwa
  • 3,639
  • 3
  • 37
  • 62
3
votes
2 answers

rSpec Shoulda matchers testing validations

I have the following validation on an attribute of a model: validates :on_ride_photo, presence: true, inclusion: { in: [true, false] } I then have the following tests: context 'on_ride_photo' do it { should…
rctneil
  • 7,016
  • 10
  • 40
  • 83
3
votes
1 answer

How to override setup values, like RSpec `let`, in shoulda contexts?

Here's a nice technique I use with RSpec that I would also like to use in projects that use Shoulda and Shoulda-context. But I don't know if it's possible. Is there a way to do this? What I want: define a setup (before) block in an outer context…
Brian Morearty
  • 2,794
  • 30
  • 35
3
votes
0 answers

rails 3 + shoulda + validations based on callbacks

i am new to shoulda. many of my models have validations as below validates :sampling_method, :presence => true, :if => :type_of_resource validate :check_for_decimal_places, :if => :is_size_and_gdnt, :on => :update here, type_of_resource and…
Prasad Surase
  • 6,486
  • 6
  • 39
  • 58
3
votes
1 answer

Rails rspec - how to check model for validation that has ", if: :direct" clause

I have this model code: validates_presence_of :setting_id validates_presence_of :user_id validates_presence_of :topic_id, if: :direct? I have these rspec tests: it { should validate_presence_of :setting_id } it { should validate_presence_of…
Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
3
votes
2 answers

Rspec / shoulda: testing, that a custom validator is called

I have a custom validator (located in app/validators/uri_validator.rb) which is used in: validates :link, uri: true How do I specify this in my specs? Ideally I would like to have a one-line call, such as: it { should validate_uri_of(:link) } How…
krn
  • 6,715
  • 14
  • 59
  • 82
3
votes
2 answers

Rails: One-to-many foreign key incorrect

I am relatively new to rails. I am trying to set a one-to-many association in rails. However, I think I am doing something wrong with my foreign_key since my test is failing. My test is the following: In user_spec: it {should have_many…
Karan
  • 14,824
  • 24
  • 91
  • 157
2
votes
2 answers

Alternatives to Shoulda?

When developing a project, I turned to shoulda for testing just because it's what I was familiar with. However, the project hasn't had a release in over a year. I'm wondering if anyone has recommendations on alternatives, or if I should just stick…
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
2
votes
0 answers

Clearance + Shoulda Matchers not loading on RSpec

I added the following lines to my spec_helper.rb file require 'clearance/testing' require 'clearance/shoulda_macros' config.include Clearance::Shoulda::Helpers But I'm getting the following…
thoughtpunch
  • 1,907
  • 4
  • 25
  • 41
2
votes
2 answers

Disable render when testing a controller

I'm using Test::Unit with shoulda to test a controller. Since I'm just testing the controller I dont wanna the view to be rendered. I'm stubbing some objects, some errors are throw when the view is rendered, but the test shouldn't fail, because the…
Rafael Mueller
  • 6,028
  • 3
  • 24
  • 28
2
votes
1 answer

Shoulda, Rails Tests , and Autotest

I'm trying to model my tests after the great work that the Thougtbot guys have done. They seem to use the test framework built into Rails Shoulda. Great. I have been hearing a lot about Autotest - that its magical-ness should make things easier....…
Bill
  • 1,563
  • 1
  • 15
  • 28
2
votes
1 answer

Shoulda validation for multiple attributes on one line?

With the older Shoulda plugin I was using, I used to be able to do something like the following: should_have_many :posts, :authors, :comments After upgrading my version of Shoulda, I had to change it to something like this: should have_many…
blim8183
  • 768
  • 1
  • 8
  • 23
2
votes
3 answers

Why has shoulda controller test assign_to no access to instance variable?

For my Rails 3 application I use FactoryGirl together with shoulda context (1.0.0.beta1) and matchers (1.0.0.beta3) for my functional tests. My problem: in the code example below, the assign_to test fails because @user - to my surprise - turns out…
dblp1
  • 35
  • 2