2009-06-05 60 views
0

我正在查看Datamapper目錄並打開了dm-core/tasks/dm.rb。總的來說,這個文件到底發生了什麼?它對我來說看起來像希臘語。特別是關於「規格」的這件事 - 這些是爲了什麼?這與定義項目應包含的軟件規範類似嗎?什麼是Ruby寶石的「規格」?

require 'spec/rake/spectask' 
require 'spec/rake/verify_rcov' 

task :default => 'spec' 

RCov::VerifyTask.new(:verify_rcov => :rcov) do |t| 
    t.threshold = 87.7 # Make sure you have rcov 0.7 or higher! 
end 

def run_spec(name, files, rcov) 
    Spec::Rake::SpecTask.new(name) do |t| 
    t.spec_opts << '--options' << ROOT + 'spec/spec.opts' 
    t.spec_files = Pathname.glob(ENV['FILES'] || files.to_s).map { |f| f.to_s } 
    t.rcov = rcov 
    t.rcov_opts << '--exclude' << 'spec' 
    t.rcov_opts << '--text-summary' 
    #t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse' 
    #t.rcov_opts << '--only-uncovered' 
    #t.rcov_opts << '--profile' 
    end 
end 

public_specs  = ROOT + 'spec/public/**/*_spec.rb' 
semipublic_specs = ROOT + 'spec/semipublic/**/*_spec.rb' 
all_specs  = ROOT + 'spec/**/*_spec.rb' 

desc 'Run all specifications' 
run_spec('spec', all_specs, false) 

desc 'Run all specifications with rcov' 
run_spec('rcov', all_specs, true) 

namespace :spec do 
    desc 'Run public specifications' 
    run_spec('public', public_specs, false) 

    desc 'Run semipublic specifications' 
    run_spec('semipublic', semipublic_specs, false) 
end 

namespace :rcov do 
    desc 'Run public specifications with rcov' 
    run_spec('public', public_specs, true) 

    desc 'Run semipublic specifications with rcov' 
    run_spec('semipublic', semipublic_specs, true) 
end 

desc 'Run all comparisons with ActiveRecord' 
task :perf do 
    sh ROOT + 'script/performance.rb' 
end 

desc 'Profile DataMapper' 
task :profile do 
    sh ROOT + 'script/profile.rb' 
end 

回答

4

你真正擁有的是一個rake文件,它調用rspec測試。實際的規格將在名爲foo_spec.rb的文件中,並且更具可讀性。

RSpec是行爲驅動開發(BDD)的框架,用於替代測試單元中的傳統單元測試框架。

使用BDD超過傳統的單元測試的真正好處是具有可讀性測試,這些測試完全可以看作是規範。

我經常與非技術客戶坐在一起,閱讀規範的源文件,看看他們是否有意義或缺少任何規則。在幾乎所有情況下,他們都可以智能地跟蹤他們。

這是一個愚蠢的簡單的例子:由於其他海報說,到RSpec web site更多信息

describe User do 
    describe "basic generation" do 
    before(:each) do 
     @user=User.create :first_name=>"Bob, :last_name=>"Smith" 
    end 

    it "should be valid" do 
     @user.should be_valid 
    end 

    it "should have a full name" do 
     @user.full_name.should=="Bob Smith" 
    end 
    end 
end 

0

是的。

規範文件包含行爲驅動開發的規範。檢出rspec

eta:我剛剛讀了你的問題更徹底。您正在查看的文件是rake文件。它呼籲規範運行你的BDD規範。