My methods :
Shoulda::Context.send(:include, Module.new do
def when_reminder_sent(n, &blk)
context "when reminder #{n} was sent" do
setup { subject.free_trial_notice_sent = n }
blk.bind(self).call
end
end
def when_payment_was_received(&blk)
context 'when payment has been received' do
setup { subject.last_payment_received_at = 1.day.ago }
blk.bind(self).call
end
end
end)
It injects and returns true. So I know its in there. But when I do :
context 'on day 15' do
when_reminder_sent(15) { should('be nil') { assert_nil subject.reminder_to_send }}
It returns :
NoMethodError: undefined method `when_reminder_sent' for EnterpriseRegistrationTest:Class
Ah so I see its trying to use this method on my tested Model.. how can I ensure that it is using the method within its original Shoulda context?
*edit : fixed some typos *
dyld: DYLD_ environment variables being ignored because main executable (/bin/ps) is setuid or setgid
/Users/elephanttrip/.rvm/gems/ruby-1.9.3-p125@website/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:230: Use RbConfig instead of obsolete and deprecated Config.
/Users/elephanttrip/.rvm/gems/ruby-1.9.3-p125@website/gems/shoulda-context-1.1.6/lib/shoulda/context/context.rb:474:in `method_missing': undefined method `when_reminder_sent' for EnterpriseRegistrationTest:Class (NoMethodError)
from /Users/elephanttrip/Sites/website/test/unit/enterprise_registration_test.rb:578:in `block (5 levels) in <class:EnterpriseRegistrationTest>'
from /Users/elephanttrip/.rvm/gems/ruby-1.9.3-p125@website/gems/shoulda-context-1.1.6/lib/shoulda/context/context.rb:322:in `instance_exec'
from /Users/elephanttrip/.rvm/gems/ruby-1.9.3-p125@website/gems/shoulda-context-1.1.6/lib/shoulda/context/context.rb:322:in `merge_block'
So I just rewrote this and threw it at the beginning of the test. Evidently this module injection isn't properly coded for the upgrade.
Winning Answer
class MyMassiveObjectTest < ActiveSupport::TestCase
def self.when_reminder_sent(n, &blk)
context "when reminder #{n} was sent" do
setup { subject.free_trial_notice_sent = n }
blk.bind(self).call
end
end
def self.when_payment_was_received(&blk)
context 'when payment has been received' do
setup { subject.last_payment_received_at = 1.day.ago }
blk.bind(self).call
end
end