Sha256: 7747fa85987ae2ba71bbc40ff4569d1d8df64ada9706261364bacfb383e121dd

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

require 'spec_helper'
require 'muzang-plugins/muzang-reddit'

class Reddit
  def period
    0.1
  end
end

describe "Reddit" do
  before do
    @bot = stub
    @reddit = Reddit.new(@bot)
    @connection = ConnectionMock.new(:nick => "DRUG-bot")
    @message = OpenStruct.new({ :command => :join, :channel => "#test", :nick => "DRUG-bot" })
    @file = File.expand_path('../support/responses/reddit.response', __FILE__)
    EventMachine::MockHttpRequest.pass_through_requests = false
    EventMachine::MockHttpRequest.register_file('http://www.reddit.com:80/r/ruby/.rss', :get, @file)
    EventMachine::MockHttpRequest.activate!
  end

  it "should call reddit and print all articles" do
    @reddit.last_update = Time.new 2010
    EM.run do
      @reddit.call(@connection, @message)
      eventually(25) { @connection.message_count }
    end
  end

  it "should print only one message" do
    @reddit.last_update = (DateTime.parse "Thu, 29 Sep 2011 00:47:00 +0200").to_time
    EM.run do
      @reddit.call(@connection, @message)
      eventually(1, :every => 0.1, :total => 20) { @connection.message_count }
    end
  end

  it "should not print message" do
    @reddit.last_update = Time.now
    EM.run do
      @reddit.call(@connection, @message)
      eventually(0) { @connection.message_count }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
muzang-plugins-1.1.4 spec/reddit_spec.rb
muzang-plugins-1.1.3 spec/reddit_spec.rb
muzang-plugins-1.1.2 spec/reddit_spec.rb
muzang-plugins-1.1.1 spec/reddit_spec.rb
muzang-plugins-1.1.0 spec/reddit_spec.rb