Home > article > test/unitで書いたテストにRSpecでテストを追記する方法

test/unitで書いたテストにRSpecでテストを追記する方法

10分ぐらい調べて試してみただけだけど。

require 'rubygems'
require 'test/unit'
require 'spec'

class TestArray < Test::Unit::TestCase

  # test/unit
  def test_1
    assert_equal(0, Array.new.size)
  end

  # rspec
  describe Array, "when empty" do
    before do
      @empty_array = []
    end

    it "should be empty" do
      @empty_array.should be_empty
    end

    it "should size 0" do
      @empty_array.size.should == 0
    end

    after do
      @empty_array = nil
    end
  end
end
$ ruby test.rb
....

Finished in 0.007974 seconds

4 examples, 0 failures

RSpecの方のテストはるびまの角谷さんの記事から拝借しました。

spceをrequireして、クラスに書きこんでいけばよさそう。仕事だとtest/unitで書いてしまったテストも多いだろうから、test/unitからRSpecに移行するのにいいかもしれない。

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://ukstudio.jp/2008/03/04/from_unittest_to_rspec/trackback/
Listed below are links to weblogs that reference
test/unitで書いたテストにRSpecでテストを追記する方法 from UKSTUDIO

Home > article > test/unitで書いたテストにRSpecでテストを追記する方法

Feeds
Meta
Others

Return to page top