Roll your own shoulda macros
I wanted a good tutorial and I found it:
excerpt:
class Test::Unit::TestCase
def self.should_have_attr_reader name
klass = self.name.gsub(/Test$/, '').constantize
should "have attr_reader :#{name}" do
obj = klass.new
obj.instance_variable_set("@#{name}", "SomeSecretValue")
assert_equal("SomeSecretValue", obj.send(name))
end
end
end
# Usage
class PostTest
should_have_attr_reader :comments_number
end
Cascaded Contexts in Ruby - Tests
There is Shoulda which does an excellent job.
But for people with less need for cool features, this might be good:
GNU nano 2.2.4 File: README.markdown
@value += 1
end
should "equal 2" do
assert_equal 2, @value
end
end
end
You can run it normally, it's Test::Unit after all. If you want to run a particular test, say "yet more tests", try this:
$ testrb my_test.rb -n test_yet_more_tests
Or with a regular expression:
$ testrb my_test.rb -n /yet_more_tests/
Installation
------------
$ sudo gem install contest
If you want to use it with Rails, add this to config/environment.rb:
config.gem "contest"
Then you can vendor the gem:
rake gems:install
rake gems:unpack