Create a new directory
> mkdir foo
> cd foo
Install bundler
> gem install bundler
Create a gem file and add the following gem
> vi Gemfile
source 'https://rubygems.org' gem 'minitest', '~> 5.3.4'
> bundle install
Create the following directory structure
> mkdir lib test
Create a class
> vi lib/meme.rb
class Meme def i_can_has_cheezburger? "OHAI!" end def will_it_blend? "YES!" end end
Create a minitest
> vi test/test_meme.rb
require "minitest/autorun" require_relative '../lib/meme' class TestMeme < Minitest::Test def setup @meme = Meme.new end def test_that_kitty_can_eat assert_equal "OHAI!", @meme.i_can_has_cheezburger? end def test_that_it_will_not_blend refute_match /^no/i, @meme.will_it_blend? end def test_that_will_be_skipped skip "test this later" end end
or BDD style
require 'minitest/autorun' require_relative '../lib/meme' describe Meme do before do @meme = Meme.new end describe 'when asked about cheeseburgers' do it 'must respond positively' do @meme.i_can_has_cheezburger?.must_equal 'OHAI!' end end end
Run the test
> ruby test/test_meme.rb
3 runs, 3 assertions, 0 failures, 0 errors, 1 skips
Voila!
Links that help
http://ruby.learncodethehardway.org/book/ex46.html
http://www.airpair.com/testing/learn-ruby-test-driven-development
https://github.com/seattlerb/minitest
http://bundler.io/
Leave a Reply