Help us understand the problem. What is going on with this article?

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

More than 5 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"
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away