shoulda

Rspec + Shoulda + FactoryGirl = undefined method `reflect_on_association'

I have Rspec + Shoulda + FactoryGirl and I am receiving the following error when attempting to call Shoulda's have_many or belong_to methods. All Shoulda methods used in the "validations" group work fine: > NoMethodError in 'A Project > associations should When you call a > matcher in an example without a > String, like this: > > s...

How to repeat a test case without duplicate code?

Hi, I'm using shoulda with Ruby on Rails, and I have the following test cases: class BirdTest < Test::Unit::TestCase context "An eagle" do setup do @eagle = Eagle.new end should "be able to fly" do assert_true @eagle.can_fly? end end context "A Crane" do setup do @cra...

Rails testing with factories. Transactional uniqueness problem.

I keep getting validation errors when running factories due to uniqueness constraints on fields. I am using shoulda with factory_girl. I have a both a unit test and a functional test creating 2 products in the database. I can run 'rake test:units' and 'rake test:functionals' over and over in any order and everything is will be green b...

Facebooker Causing Problems with Rails Integration Testing

I am (finally) attempting to write some integration tests for my application (because every deploy is getting scarier). Since testing is a horribly documented feature of Rails, this was the best I could get going with shoulda. class DeleteBusinessTest < ActionController::IntegrationTest context "log skydiver in and" do setup do...

Error when logging in with Machinist in Shoulda test

I am having some trouble getting the right usage of Machinist and Shoulda in my testing. Here is my test: context "on POST method rating" do p = Product.make u = nil setup do u = login_as post :vote, :rating => 3, :id => p end should "set rating for product to 3" do assert_equal p.get_user_vote(u), 3 end And here's my bluepri...

What's the point of some of shoulda's macros?

I think shoulda is really neat, but what I don't understand is why some of the macros exist, such as: should_validate_uniqueness_of :title should_validate_presence_of :body, :message => /wtf/ should_validate_presence_of :title should_validate_numericality_of :user_id I'm relatively new to testing, but what purpose do these serve? The...

shoulda macros with rspec2 beta 5 and rails3 beta2

I've setup Rspec2 beta5 and shoulda as following to use shoulda macros inside rspec model tests. Gemfile group :test do gem "rspec", ">= 2.0.0.beta.4" gem "rspec-rails", ">= 2.0.0.beta.4" gem 'shoulda', :git => 'git://github.com/bmaddy/ shoulda.git' gem "faker" gem "machinist" gem "pickle", :git => 'git:/...

How do I assert that a model has a readable/writable attribute?

In one of my model's I'm using some meta programming to dynamically define some methods. I'd like to test this; thus, I need a compact way to assert my model has a readable/writable attribute with a certain name. Ideas? I'm using shoulda for unit testing if it makes a difference. ...

Shoulda: How would I use an instance variable outside of a setup or should block?

I'm trying to do something like the following: @special_attributes = Model.new.methods.select # a special subset @special_attributes.each do |attribute| context "A model with #{attribute}" do setup do @model = Model.new end should "respond to it by name" do assert_respond_to @model, attribute end end end ...

when does factory girl create objects in db?

i am trying to simulate a session using factory girl/shoulda (it worked with fixtures but i am having problems with using factories). i have following factories (user login and email both have 'unique' validations): Factory.define :user do |u| u.login 'quentin' u.email '[email protected]' end Factory.define :session_user, :class =...

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 context "some context" do macro_context do should "test" do fail ...

How do I setup and utilize Shoulda, Factory_Girl, and Cucumber in a Rails 3 application?

I'm able to get my Gemfile how I like it: # Gemfile source "http://gemcutter.org" gem "rails", :git => "git://github.com/rails/rails.git" git "git://github.com/rails/arel.git" git "git://github.com/rails/rack.git" gem "sqlite3-ruby" group :test do gem "shoulda", :git => "git://github.com/thoughtbot/shoulda.git", :branch => ...

Autotest, Shoulda, Ruby - The Setup?

I am trying to get the whole setup working with Autotest/Growl/Shoulda on my Mac to test a gem I'm working on for Authlogic. I've used RSpec in the past quite a bit but would like to switch to Shoulda. This gem is going to work with Rails, but others gems I've made are just plain old ruby libraries with no dependencies on Rails modules...

Testing devise with shoulda

Hello, I'm having some difficulties in testing devise with shoulda: 2) Error: test: handle :index logged as admin should redirect to Daily page. (Admin::DailyClosesControllerTest): NoMethodError: undefined method `env' for nil:NilClass devise (1.0.6) [v] lib/devise/test_helpers.rb:52:in `setup_controller_for_warden' I have this in my...

Weird error when trying to test method with argument in Mocha. Is it a bug or is it me?

Hi there. It's rather hard to find any documentation on Mocha, so I'm afraid I'm totally at sea here. I have found a problem with stubbing methods that pass arguments. So for instance if I set up a class like this: class Red def gets(*args) @input.gets(*args) end def puts(*args) @output.puts(*args) end def initial...

Mongomapper - unit testing with shoulda on rails 2.3.5

I'm trying to implement shoulda unit tests on a rails 2.3.5 app using mongomapper. So far I've: Configured a rails app that uses mongomapper (the app works) Added shoulda to my gems, and installed it with rake gems:install Added config.frameworks -= [ :active_record, :active_resource ] to config/environment.rb so ActiveRecord isn't us...

Rails Controller Tests for Captcha using Shoulda, Factory Girl, Mocha

Can someone provide a strategy/code samples/pointers to test Captcha validations + Authlogic using Shoulda, Factory Girl and Mocha? For instance, my UsersController is something like: class UsersController < ApplicationController validates_captcha ... def create ... if captcha_validated? # code to deal with user attributes end ....

Rails shoulda and factory_girl setup

I have installed both shoulda and factory_girl, I can run shoulda just fine, but when I add this: require 'factory_girl' Factory.define :user do |u| u.mail '[email protected]' u.pass 'secret' end to my test/test_helper.rb I'm getting this error: /test/test_helper.rb:1:in `require': no such file to load -- factory_girl (LoadError)...

Shoulda and Paperclip testing

I am trying to test a couple models that have an attachment with Paperclip. I have all of my validations passing except for the content-type check. # myapp/test/unit/project_test.rb should_have_attached_file :logo should_validate_attachment_presence :logo should validate_attachment_size(:logo).less_than(1.megabyte) should_validate_atta...

Shoulda testing format

I am trying to test a model's attributes for formatting with this: # myapp/test/unit/comment_test.rb require 'test_helper' class CommentTest < ActiveSupport::TestCase should_belong_to :article should_validate_presence_of :name should_validate_presence_of :email should_validate_presence_of :content should_validate_presence_of...