尝试使用RSpec在Rails中模拟TwitterAPI客户端

时间:2015-09-28 22:07:16

标签: ruby-on-rails twitter rspec mocking stub

我有一些功能可以获得一些推文,我只是想添加一些简单的测试:

def get_tweets_in_time_range(search, since_time, until_time)
    client = TwitterAPI.new.client

    begin
        return client.search(
            search,
            include_entities: true,
            result_type: "recent",
            since: since_time.to_date, 
            until: until_time.to_date
        )
    rescue Twitter::Error::Unauthorized
        dispatch_error "Unauthorized credentials"
        return []
    end
end 

所以我开始编写一个看起来像这样的测试:

it "should return tweets when successful" do 
    allow_any_instance_of(TwitterAPI::Client).to receive(:search).with(@search, @since_time, @until_time).and_return(unprocessed_tweets(3, @tag_name, @now-1.weeks, @now))
end

当我运行时,我收到错误:

  

NameError:   未初始化的常量TwitterAPI :: Client

这是怎么回事?谢谢你的帮助。

0 个答案:

没有答案