Hol*_*ola 5 ruby rubygems ruby-on-rails
我正在浏览 Datamapper 目录并打开dm-core/tasks/dm.rb. 一般来说,这个文件到底发生了什么?对我来说它看起来像希腊语。特别是关于“规格”的事情 - 那些是用来做什么的?这是否类似于定义项目应包含的内容的软件规范?
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
Run Code Online (Sandbox Code Playgroud)
小智 7
您实际上拥有的是一个调用 rspec 测试的 rake 文件。实际的规格将位于名为 foo_spec.rb 的文件中,并且更具可读性。
RSpec 是行为驱动开发 (BDD) 的框架,用作 Ruby 中传统单元测试框架 testunit 的替代方案。
与传统单元测试相比,使用 BDD 的真正好处之一是拥有可读的测试,这些测试实际上可以读作规范。
我经常与非技术客户坐在一起,通读规范源文件,看看它们对他们是否有意义,或者是否缺少任何规则。几乎在所有情况下,他们都能明智地遵循它们。
这是一个愚蠢的简单例子:
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
Run Code Online (Sandbox Code Playgroud)
正如另一位发帖者所说,请访问RSpec 网站了解更多信息。
| 归档时间: |
|
| 查看次数: |
6529 次 |
| 最近记录: |