The document discusses various configuration options and examples for using RSpec, a testing framework for Ruby. It provides examples of configuring RSpec using a spec_helper file, filtering runs by context or version of Ruby, and defining custom matchers for assertions.
1 of 24
Downloaded 35 times
More Related Content
RSpec 1.x -> 2.0 の変更点
1. Chiew Chung @theworldinunion
Edward Middleton @e14n
12. describe "something" do
context "in some context" do
it "does something" do
# ...
end
end
end
15. # in spec/spec_helper.rb
RSpec.configure do |c|
c.filter_run :focus => true
end
# in any spec file
describe "something" do
it "does something", :focus => true do
# ....
end
end
16. RSpec.configure do |c|
c.filter_run :focus => true
c.run_all_when_everything_filtered = true
end
17. # in spec/spec_helper.rb
RSpec.configure do |c|
c.exclusion_filter = { :ruby => lambda {|version|
!(RUBY_VERSION.to_s =~ /^#{version.to_s}/)
}}
end
# in any spec file
describe "something" do
it "does something", :ruby => 1.8 do
# ....
end
it "does something", :ruby => 1.9 do
# ....
end
end
22. def eat_cheese
simple_matcher("eat cheese") do |actual|
actual.eat?(:cheese)
end
end
RSpec::Matchers.define :eat_cheese do
match do |actual|
actual.eat?(:cheese)
end
end
23. RSpec::Matchers.define :eat_cheese do
match do |actual|
actual.should eat?(:cheese)
end
end
RSpec::Matchers.define :eat_cheese do
include MyCheesyAssertions
match_unless_raises
Test::Unit::AssertionFailedError do |actual|
assert_eats_chesse actual
end
end