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

Why is this test result backwards?

I'm writing my first tests using Test:Unit and Shoulda, so this may be a simple misunderstanding on my part, but given a Pages model that contains no validation, and a test: #test/unit/page_test.rb require 'test_helper' class PageTest <…
Matt
  • 3,682
  • 1
  • 21
  • 27
4
votes
1 answer

Shoulda rspec matchers ensure_inclusion_of

I have a test using shoulda that is failing for reasons I don't understand. Any idea what the fix is for this? I hardcoded the array for testing purposes. All my other shoulda matcher based tests are working fine. Validation validates_inclusion_of…
David R
  • 328
  • 1
  • 15
3
votes
0 answers

Rails: how to test should_render_template [or similar] for full view path?

OK, lets say I'm rendering a view from an oddball path, think: prepend_view_path 'app/custom_views' I'd like to test that the view gets rendered from this path like: should_render_template 'app/custom_views/controller/action' However this matcher…
whatbird
  • 1,552
  • 1
  • 14
  • 25
3
votes
2 answers

ShouldaMatchers validate_uniquess_of scoped to multiple columns

I have a model with a unique index at the db level and model validation checking for uniqueness scoped to multiple columns. # db level add_index :table1, %i[fk_belongs_to_id col1 col2 col3 col4], unique: true # model level validates…
3
votes
4 answers

How do I make one line tests in Rspec without Shoulda?

I have a bunch of very repetitive rspec tests that all have the same format: it "inserts the correct ATTRIBUTE_NAME" do @o.ATTRIBUTE_NAME.should eql(VALUE) end It would be nice if I could just make one line tests…
Jeremy Smith
  • 14,727
  • 19
  • 67
  • 114
3
votes
2 answers

Why is this Rails controller test failing?

I'm trying to understand why this test is failing. (I'm kind of new to testing.) I'm using the built-in Rails testing framework with the addition of the Shoulda gem. The test: require 'shoulda' context "on GET to :new" do setup do get(:new) …
Ethan
  • 57,819
  • 63
  • 187
  • 237
3
votes
4 answers

How do you test whether a model has a given method in Rails?

I would like to implement the method User.calculate_hashed_password. I'm trying to use the Shoulda testing library which works with Rails's built-in testing tools, so an answer related to Test::Unit would be just as good as one related to Shoulda (I…
Ethan
  • 57,819
  • 63
  • 187
  • 237
3
votes
1 answer

Setting up Shoulda under Test/Unit in Rails 3 (3.0.3)

I have posted this in other places but no response. Trying to get Shoulda working inside Test/Unit in Rails 3.0.3 (1.9.2). When I try to run the test (copied below), I get this error: test/unit/practice_member_test.rb:4:in…
David Kahn
  • 31
  • 1
3
votes
1 answer

Adding custom shoulda matchers to TestCase

After using shoulda it is very clear that shoulda no longer uses macros (They are all deprecated for the preferred matchers) For example: should_allow_custom_test is deprecated for the following: should allow_custom_test However all the…
Sukima
  • 9,965
  • 3
  • 46
  • 60
3
votes
2 answers

Mocking/Stubbing an Application Controller method with Mocha (Using Shoulda, Rails 3)

While writing functional tests for a controller, I came across a scenario where I have a before_filter requesting some information from the database that one of my tests requires. I'm using Factory_girl to generate test data but I want to avoid…
Christian
  • 135
  • 3
  • 7
3
votes
2 answers

assigns_to doesn't work for Rails 3 Shoulda on Ubuntu

I'm using Rails3 with rspec and shoulda. I have the below spec describe PagesController, "on GET to show while logged off" do before(:each) do @site = Factory.create(:site) @site.domains << Factory.create(:domain) @site.save! …
3
votes
1 answer

shoulda should "be valid" do fails with "'handle_matcher': undefined method 'matches?'"

I'm trying out 'shoulda' on top of rspec (rails 3) with the following spec: require 'spec_helper' describe Article do should "be true" do assert true end end and it fails…
Jeppe Liisberg
  • 3,734
  • 3
  • 25
  • 24
3
votes
2 answers

Test Driven Development - Should I test database columns and indexes?

I am new to TDD. I find that the shoulda gem has the ability to test if a column exists for a database entity as well as the ability to test its indexes. But is it necessary to include testing of columns and indexes in my test suite? Will I need to…
donkey
  • 4,285
  • 7
  • 42
  • 68
3
votes
1 answer

Factory Girl with has many relationship (and a protected attribute)

I have this kind of relation: class Article < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :article attr_protected :article_id end The default scenario inside controllers looks like: @article =…
3
votes
1 answer

Unable to test should belong_to, missing id foreign key on Rails

Hello I have been looking for a way to test model relationship and stumble upon should gem shoulda (3.5.0) shoulda-context (1.2.1) shoulda-matchers (2.8.0) Unfortunatly I tried to test a simple example with rspec describe Region do it …
Necronet
  • 6,704
  • 9
  • 49
  • 89