Thanks Ryan. Your answer to Bharat's question solved my problem with
upgrading tests of an ActiveRecord singleton to Shoulda 2.10.1. You
talk about the subject block in the future tense - but the rdocs at
http://rdoc.info/projects/thoughtbot/shoulda seem to indicate that
using the subject class method is the current preferred way to deal
with this.
subject(&block)
Sets the return value of the subject instance method:
class UserTest < Test::Unit::TestCase
subject { User.first }
# uses the existing user
should_validate_uniqueness_of :email
end
I tried an example that is essentially like that (I used the
should_allow_values_for method but...). I tried it with and without an
enclosing context and in both cases I got:
undefined method `subject' for SitePreferenceTest:Class (NoMethodError)
Am I just running into a version difference between what I installed
as a gem (2.10.1) and what version the rdocs are referring to
(Generated at 06/10/09 00:38:05 +00:00 from 1806451b...)? Or is there
something fundamental I am missing?
--
Cynthia Kiser
c...@caltech.edu
You
talk about the subject block in the future tense - but the rdocs at
http://rdoc.info/projects/thoughtbot/shoulda seem to indicate that
using the subject class method is the current preferred way to deal
with this.
undefined method `subject' for SitePreferenceTest:Class (NoMethodError)
Am I just running into a version difference between what I installed
as a gem (2.10.1) and what version the rdocs are referring to
(Generated at 06/10/09 00:38:05 +00:00 from 1806451b...)?
Cool! (even though I think that means it will break a number of my
tests).
So I have what smells to me like the same sort of problem - except
that I went out and generated my own copy of the rdocs from my
installed version of shoulda. I see the macro I am calling
(should_redirect_to) documented, with an example that looks like what
I am going - but my tests can't use it. What am I missing?
I am upgrading an app from Rails 2.1 -> 2.3.2 and more relevant for
this discussion from Shoulda 2.0.6 installed as a plugin to Shoulda
2.10.1 installed as a gem (+ config.gem line in environment.rb). Yes I
should have done these sequentially - starting with upgrading Shoulda,
but.... After a few syntax changes, my unit tests all pass and now I
am starting in on the functional tests. FWIW, manual testing via a
browser confirms that the user index page does indeed redirect if you
are not logged in first.
require File.dirname(__FILE__) + '/../test_helper'
class UsersControllerTest < ActionController::TestCase
context "User actions" do
setup do
# check to see if login_url is evaluated to what I expect
puts login_url
end
should "test the test" do
get :index
should_redirect_to("the login page") { login_url }
end
end
end
$ ruby -I test test/functional/users_controller_test.rb
1) Error: test: User actions should test the test. (UsersControllerTest):
NoMethodError: undefined method `should_redirect_to' for #<UsersControllerTest:0xb145978>
test/functional/users_controller_test.rb:16:in `__bind_1245455972_115540'
/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `call'
/software/stow/ruby-enterprise-1.8.6-20080709/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in `test: \
User actions should test the test. '
--
Cynthia Kiser