Skip to content

Instantly share code, notes, and snippets.

@tosik
Created May 24, 2010 16:25
Show Gist options
  • Save tosik/412089 to your computer and use it in GitHub Desktop.
Save tosik/412089 to your computer and use it in GitHub Desktop.
example for rspec and rcov
class Calc
def initialize
@value = 0
end
def add(value)
@value += value
end
def sub(value)
@value -= value
end
def div(value)
@value /= value
end
attr_reader :value
end
require "Calc"
describe Calc do
describe "when be made" do
before :each do
@calc = Calc.new
end
it "value should be zero" do
@calc.value.should be_zero
end
end
describe "when be made and add 10" do
before :each do
@calc = Calc.new
@calc.add(10)
end
it "value should be ten" do
@calc.value.should == 10
end
end
describe "when be made and subtract 15" do
before :each do
@calc = Calc.new
@calc.sub(15)
end
it "value should be minus fifteen" do
@calc.value.should == -15
end
end
describe "when be made, add 6 and divide by 2" do
before :each do
@calc = Calc.new
@calc.add(6)
@calc.div(2)
end
it "value should be three" do
@calc.value.should == 3
end
end
end
require 'rake'
require 'spec/rake/spectask'
task :default => "rspec_with_rcov"
Spec::Rake::SpecTask.new('rspec_with_rcov') do |t|
t.spec_files = FileList['**/*_spec.rb']
t.libs << "./"
t.rcov = true
t.spec_opts = ['--format', 'nested', '--color']
t.rcov_opts = ['--exclude', 'spec']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment