`
swachian
  • 浏览: 73511 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

用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/

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics