用RSpec来test

http://delynnberry.com/projects/acts-as-dropdown/

 

安装RSpec http://rspec.info/documentation/rails/install.html

ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/CURRENT/rspec_on_rails

 gem install rspec

 

arbitrary predicate.

the magic of method_missing

 

target.should be_true
target.should be_false
target.should be_nil
target.should_not be_nil

collection.should be_empty #passes if target.empty?
target.should_not be_empty # passes unless target.empty?
target.should_not be_under_age(13) # passes unless target.under_age?(13)


“a string”.should be_an_instance_of(String)
3.should be_a_kind_of(Fixnum)
3.should be_a_kind_of(Numeric)
3.should be_an_instance_of(Fixnum)
3.should_not be_instance_of(Numeric) #fails



 

describe “people in general”, :shared => true do
  it “should have a name” do
    @person.name.should_not be_nil
  end
  it “should have an age” do
    @person.age.should_not be_nil
  end
end

describe Teacher do
  before(:each) do
    @person = Teacher.new(“Ms. Smith”, 30, 50000)
  end
  
  it_should_behave_like “people in general”
  
  it “should have a salary” do
    @person.salary.should == 50000
  end
end

 :each :all

 

运行方式

ruby script/generate rspec

ruby script/generate rspec_model LeaveNumberLog(ruby script/generate rspec _scaffold User name:string age:integer )

 

编写

 

ruby script\spec_server

spec --drb spec\models\leave_number_log_spec.rb

或者

ruby script/spec spec

group controller examples by action and HTTP method.

 

 

 

rake db:fixtures:load FIXTURE=table1,table2

把夹具里面的数据导到dev环境中。

 

ruby script/plugin install  http://www.realityforge.org/svn/public/code/debug-view-helper/trunk/

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值