Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

RSpec 1.x -> 2.0 の変更点

4,776 views

Published on

RSpec 1.x -> 2.0 の変更点

Published in: Technology
  • Be the first to comment

RSpec 1.x -> 2.0 の変更点

  1. 1. Chiew Chung @theworldinunion Edward Middleton @e14n
  2. 2. 'rspec/core/rake_task'
  3. 3. RSpec.configure do |c| # .... command line ./.rspec ~/.rspec
  4. 4. describe "something" do context "in some context" do it "does something" do # ... end end end
  5. 5. # 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
  6. 6. RSpec.configure do |c| c.filter_run :focus => true c.run_all_when_everything_filtered = true end
  7. 7. # 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
  8. 8. actual.should == expected # object equality actual.should equal(expected) # object identity actual.should eq(expected) # object equality actual.should be(expected) # object identity
  9. 9. 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
  10. 10. 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

×