Posted at

railsで任意にminitestを実行する方法

More than 3 years have passed since last update.


lib/sample.rb

class Sample

def initialize(msg)
@msg = msg
end

def say
@msg
end

def scream
@msg.to_s.upcase.to_sym
end
end



test/sample_test.rb

require 'test_helper'

require 'sample'

class SampleTest < ActiveSupport::TestCase
setup do
@sample = Sample.new :hello
end

test 'sample 1' do
assert_equal @sample.say, :hello
end

test 'sample 2' do
assert_equal @sample.scream, :HELLO
end
end



  • ファイル単位で実行する場合

$ rake test TEST=test/sample_test.rb


  • ブロック単位で実行する場合

$ rake test TEST=test/sample_test.rb TESTOPTS="--name=test_sample_2"