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

minitest vs rspec

minitest vs rspec

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

Shinichi Maeshima

June 02, 2013
Tweet

More Decks by Shinichi Maeshima

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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