用黄瓜测试EventMachine

时间:2012-05-14 22:58:23

标签: ruby cucumber eventmachine

我正在尝试为我的应用程序编写黄瓜功能和rspec测试,以便使用twitter-stream访问twitter流API。我有以下代码:

Then /^I should see the latest (\d+) tweets from my timeline$/ do |num|
  timeline = Starling::Timeline::Mine.new(@store)

  EventMachine::run {
    tweets = timeline.latest
    timeline.stop
  }

  tweets.length.should == num.to_i
end

该方法的代码是:

def latest
  token = @token.get_token

  @stream = Twitter::JSONStream.connect(options)

  items = []
  @stream.each_item do |item|
    items << item
  end

  items
end

但是,可以预见的是,它会停留在timeline.latest调用上。如何正确测试latest方法中的逻辑?

0 个答案:

没有答案