Upgrade to Pro — share decks privately, control downloads, hide ads and more …

minitest vs rspec

minitest vs rspec

minitest って rspec と比較してどうなのか?現状で Rails のテスト用に使えるのか?ということについて書いています。

6ac7c50770603b53964d44db373e8e48?s=128

Shinichi Maeshima

June 02, 2013
Tweet

Transcript

  1. minitest vs rspec willnet (Shinichi Maeshima)

  2. ϑϦʔϥϯεΤϯδχΞ @netwillnet

  3. ginza.rb http://www.flickr.com/photos/cromdia/2336796541/

  4. None
  5. ruby1.9 ͔Βඪ४ఴ෇ Rails4 ͔Βඪ४ςετϑϨʔϜϫʔΫ

  6. require "minitest/autorun" class Person def hello; 'hello' end end class

    TestPerson < Minitest::Test def setup @person = Person.new end def test_hello assert_equal "hello", @person.hello end end likes test-unit
  7. likes RSpec require "minitest/autorun" class Person def hello; 'hello' end

    end describe Person do before do @person = Person.new end it 'should say hello' do @person.hello.must_equal 'hello' end end
  8. RSpec ͱ minitest ͬͯԿ͕ҧ͏ͷʁ

  9. RSpec → શ෦ೖΓ minitest → ࠷খݶ

  10. RSpec → શ෦ೖΓ minitest → ࠷খݶ Rails Sinatra Padrino

  11. capybara_minitest_spec minispec-metadata minitest-ansi minitest-around minitest-capistrano minitest-capybara minitest-chef-handler minitest-ci minitest-colorize minitest-context

    minitest-debugger minitest-display minitest-emoji minitest-english minitest-excludes minitest-firemock minitest-great_expectations minitest-growl minitest-implicit-subject minitest-instrument minitest-instrument-db minitest-libnotify minitest-macruby minitest-matchers minitest-metadata minitest-mongoid minitest-must_not minitest-nc minitest-predicates minitest-rails minitest-rails-capybara minitest-reporters minitest-should_syntax minitest-shouldify minitest-spec-context minitest-spec-expect minitest-spec-magic minitest-spec-rails minitest-stub-const minitest-tags minitest-wscolor minitest_owrapper minitest_should minitest_tu_shim mongoid-minitest pry-rescue assay-minitest detroit-minitest em-minitest-spec flexmock-minitest guard-minitest guard-minitest-decisiv minitest-activemodel minitest-ar-assertions minitest-capybara-unit minitest-colorer minitest-deluxe minitest-extra-assertions minitest-rails-shoulda minitest-spec minitest-spec-should minitest-sugar minitest_should mongoid-minitest spork-minitest minitest extensions
  12. class MyMatcher def initialize(text) @text = text end def matches?

    subject subject =~ /^#{@text}.*/ end def failure_message_for_should "expected to start with #{@text}" end def failure_message_for_should_not "expected not to start with #{@text}" end end MiniTest::Unit::TestCase.register_matcher MyMatcher, :start_with describe 'something' do it 'must start with...' do page = 'my reply' page.must_start_with 'my reply' end end minitest-matchers
  13. describe '౤ߘϖʔδʹભҠ͍ͯ͠Δͱ͖' do before { visit posts_path } it '"౤ߘ͢Δ"ϘλϯΛԡͨ͠Β"౤ߘ͠·ͨ͠"ͱදࣔ͞Ε͍ͯΔ͜ͱ'

    do click_button '౤ߘ͢Δ' page.text.must_include '౤ߘ͠·ͨ͠' end it '"࡟আ͢Δ"ϘλϯΛԡͨ͠Β confirm ͕දࣔ͞Ε͍ͯΔ͜ͱ', js: true do click_button '࡟আ͢Δ' page.driver.confirm_messages.wont_be_empty end end minitest-metadata
  14. minitest-rails adds rails support • model, controller, view • helper

    • routing • mailer
  15. ͍ΖΜͳ gem Λ૊Έ߹ΘͤΔ ͜ͱͰɺRSpec ʹ͍ۙ ػೳʹͰ͖Δ http://www.flickr.com/photos/songo/4714093882/

  16. ͕ͩ υΩϡϝϯτ͕ গͳ͍

  17. •RSpec ͷه๏͕ݏ͍ or ϒϥοΫϘοΫ εײ͕ؾ࣋ͪѱ͍ •ΧελϚΠζ޷͖ͳਓ •minitest ͷίʔυΛಡΉͷ͕ۤͰ͸ͳ͍ or minitest

    ʹৄ͍͠ਓ͕ۙ͘ʹ͍Δ ͜͏͍͏ਓʹΦεεϝ
  18. •RSpec Λطʹ࢖͍ͬͯͯ׳Ε͍ͯΔ •ϑϨʔϜϫʔΫଆͰશ෦΍ͬͯཉ͍͠೿ •ςετͱ͔Α͘Θ͔Γ·ͤΜʼʻ ͜͏͍͏ਓʹ͸ Φεεϝ͠ͳ͍

  19. ※2013೥6݄2೔ݱࡏͷঢ়گ͔Βࢉग़͞Ε͍ͯ·͢ɻ ൒೥ޙ΍̍೥ޙʹ͸ঢ়گ͕มΘ͍ͬͯΔՄೳੑ͕ߴ͍ Ͱ͢

  20. ςετϥΠϒϥϦΛ ݡ͘࢖ͬͯ ָ͍͠ςετϥΠϑ Λʂ