SlideShare a Scribd company logo
Chiew Chung        @theworldinunion
Edward Middleton   @e14n
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
'rspec/core/rake_task'
RSpec 1.x -> 2.0 の変更点
RSpec.configure do |c|
   # ....




command line
./.rspec
~/.rspec
describe "something" do
 context "in some context" do
  it "does something" do
    # ...
  end
 end
end
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
# 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
RSpec.configure do |c|
 c.filter_run :focus => true
 c.run_all_when_everything_filtered = true
end
# 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
RSpec 1.x -> 2.0 の変更点
RSpec 1.x -> 2.0 の変更点
actual.should == expected # object equality
actual.should equal(expected) # object identity




actual.should eq(expected) # object equality
actual.should be(expected) # object identity
RSpec 1.x -> 2.0 の変更点
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
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
RSpec 1.x -> 2.0 の変更点

More Related Content

RSpec 1.x -> 2.0 の変更点

  • 1. Chiew Chung @theworldinunion Edward Middleton @e14n
  • 11. RSpec.configure do |c| # .... command line ./.rspec ~/.rspec
  • 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
  • 20. actual.should == expected # object equality actual.should equal(expected) # object identity actual.should eq(expected) # object equality actual.should be(expected) # object identity
  • 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