ruby spec_helper.rb

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby spec_helper.rb相关的知识,希望对你有一定的参考价值。

require 'spec_helper'

describe "Transaction" do
  it "should handle dummy numerals" do
    transaction_input(%{
        x1    is I
        x5    is V
        x10   is X
        x50   is L
        x100  is C
        x500  is D
        x1000 is M
        how much is x1000 x100 ?
        how much is x1 x1 ?
        how much is x1 x5 ?
      }
      ).should_output(%{
        x1000 x100 is 1100
        x1 x1 is 2
        x1 x5 is 4
      })
  end
end
require "#{File.dirname(__FILE__)}/../lib/transactions.rb"
include Transactions

def capture_stdout(&block)
  original_stdout = $stdout
  $stdout = fake = StringIO.new
  begin
    yield
  ensure
    $stdout = original_stdout
  end
  fake.string
end

class TransactionInput
  def initialize output
    @output = output
  end

  def should_output output
    @output.split("\n").should == output.split("\n")[1..-2].collect{|line| line.strip}
  end
end

def transaction_input input
  TransactionInput.new capture_stdout{ input.split("\n")[1..-2].each{|line| Message.new(line).process} }
end

以上是关于ruby spec_helper.rb的主要内容,如果未能解决你的问题,请参考以下文章

ruby 01_spec_helper.rb

ruby 第1步 - 测试ElasticSearch - spec_helper.rb

困惑 - spec_helper.rb:94:在` ':未初始化的常量Shoulda(NameError)

从TextMate运行Rails的RSpec

RSpec 为 /lib 子目录中的代码引发 NameErrors

如何检测rspec文件是否作为测试套件的一部分运行