techno-weenie.net提供了两个插件simple_bdd和test_spec_on_rails,可以让你在test:unit中应用BDD而不需安装rspec,如果再加上mocha,test:unit与rspec就只存在语法的差异了。
安装:
script/plugin install http://svn.techno-weenie.net/projects/plugins/simply_bdd/
script/plugin install http://svn.techno-weenie.net/projects/plugins/test_spec_on_rails/
使用:
1. simple_bdd:
context "New User" do
def setup
end
specify "should be invalid without a username" do
end
end
这相当于:
class NewUserTest < Test::Unit::TestCase
def setup
end
def test_should_be_invalid_without_a_username
end
end
test_spec_on_rails:
#model
@user.should.validate
@user.should.be.validated
#Redirection
response.should.be.redirected # assert_response :redirect
response.should.redirect foo_url(@foo) # assert_redirected_to foo_url(@foo)
should.redirect_to :action => 'show' # because "response" is optional
更多请参看README.
另外DUST也提供和simple_bdd类似的功能。

