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

Run code after tests with shoulda context

With the standard tests there's a setup block that runs before each test. Is there something similar that we can run 'after' each test? The reason i'm asking is that my tests make requests to an outside API and i need to perform cleanup on that…
0
votes
1 answer

Test validating presence of email fails with shoulda, passes with factory girl

I'm testing that email is not required on the user model on update. With FactoryGirl: u = FactoryGirl.create(:user) u.email = nil expect(u.save).to be_true The test passes. With shoulda: should_not validate_presence_of(:email).on(:update) The…
user2517777
  • 741
  • 2
  • 7
  • 9
0
votes
3 answers

'Password digest missing on new record' when i test validation on my user_spec.rb for uniqueness of fields

I've been struggling with this for a few hours now and i can't find an answer anywhere. Basically i'm writing specs for my models using shoulda and for some reason even though my let works just fine and the actual application works fine(confirmed…
Theo Felippe
  • 279
  • 1
  • 2
  • 17
0
votes
1 answer

Testing validates length using ensure_length_of shoulda matchers

Facing a issue when i am testing this validates length with shoulda_matchers ensure_length_of Model class Plant < ActiveRecord::Base validates :code, :length => { :in => 2..6 } end Rspec require 'spec_helper' describe Plant do before { @plant…
AnkitG
  • 6,438
  • 7
  • 44
  • 72
0
votes
1 answer

Rewriting assert_bad_value for Shoulda 3

I've inherited a bunch of old (v2) Shoulda tests. The documentation on what was deprecated between v2 to v3 is quite limited, and I can't seem to find the recommended way to rewrite the "assert_bad_value" line below: context "Content page…
Adam Rubin
  • 777
  • 1
  • 7
  • 16
0
votes
1 answer

RSpec Shoulda validates_presence_of nilClass

When I use Shoulda's validates_presence_of, it stumbles on a before_validation callback. before_validation :set_document, :set_product, :set_price I'm trying to get this spec to pass: it { should…
David R
  • 328
  • 1
  • 15
0
votes
1 answer

rspec validation with unless

brief.rb # encoding: utf-8 class Brief < ActiveRecord::Base belongs_to :project validates_numericality_of :duration, :only_integer => true, :less_than_or_equal_to => 15, :greater_than_or_equal_to => 5, :unless => Proc.new{ |b|…
Johnny Cash
  • 4,867
  • 5
  • 21
  • 37
0
votes
1 answer

shoulda greater and less than syntax

brief.rb # encoding: utf-8 class Brief < ActiveRecord::Base belongs_to :project validate :can_only_be_edited_if_project_is_not_started validates_presence_of :project, :inverse_of => :brief validates_numericality_of :duration, :only_integer…
Johnny Cash
  • 4,867
  • 5
  • 21
  • 37
0
votes
1 answer

shoulda gem allow_value method

old_spec.rb it { should allow_value(:nil).for(:invoice_type) } it { should allow_value(:customer_invoice).for(:invoice_type) } it { should allow_value(:creative_invoice).for(:invoice_type) } it { should_not allow_value(:other).for(:invoice_type)…
Johnny Cash
  • 4,867
  • 5
  • 21
  • 37
0
votes
3 answers

What test framework should I use to test my Rails model?

With the many testing framework that is available in the Ruby community namely: unittest, rspec, shoulda, and coulda, what would be the most appropriate testing framework to test my Rails model? Do they basically have the same functionality, which…
Joshua Partogi
  • 16,167
  • 14
  • 53
  • 75
0
votes
1 answer

Upgrading Shoulda gem leads to errors with RSpec and Ruby on Rails

After I upgraded my shoulda gem to 3.4.0, my tests would no longer run. Context: Ruby 1.9.3-p392 Rails 3.2.12 Rspec 2.13.0 Mac OS X 10.8.3 When I set up my Gemfile and run bundle exec rspec spec I get the following errors: #Gemfile #1 group…
Randy Burgess
  • 4,835
  • 6
  • 41
  • 59
0
votes
1 answer

Test::Unit tests passing on OS X, erroring out on CentOS

I have a set of Test::Unit tests for a Rails application. It was developed on OS X under Ruby 1.8.6, Rails 2.3.4. I'm also using thoughtbot-shoulda 2.10.2. I'm using standard Rails fixtures, not factories. I've checked out the project onto a CentOS…
Ethan
  • 57,819
  • 63
  • 187
  • 237
0
votes
0 answers

What ruby testing library uses (or has used) the class-level syntax `expect {}`?

I'm refurbishing some old tests, which appear to be Test::Unit with Shoulda. Some parts have a syntax expect {block}, but I can't find any references to expect in the current Shoulda code. expect appears at the class level, where I see other setup…
Justin Love
  • 4,397
  • 25
  • 36
0
votes
1 answer

Rails Has One Rspec Test tells me Unitialized Constant

I have a have one relationship between two models. The relationship works, the problem however is that when I write a Rspec test with shoulda matchers I get returned an error. Failure/Error: it { should have_one(:userresetpassword)} NameError: …
thank_you
  • 11,001
  • 19
  • 101
  • 185
0
votes
1 answer

rspec factory girls with shoulda uniqueness test error

Good day, currently i'm struggling with this error. Failure/Error: FactoryGirl.create(:subscription) NoMethodError: undefined method `attribute_list' for "AdvtCategories":String i can't find correct solution for this error. what i found…
Elmor
  • 4,775
  • 6
  • 38
  • 70
1 2 3
25
26