spec/rubygems_spec.rb in muzang-plugins-1.0.0 vs spec/rubygems_spec.rb in muzang-plugins-1.0.1
- old
+ new
@@ -10,28 +10,66 @@
describe "RubyGems" do
before do
@bot = stub
@rubygems = RubyGems.new(@bot)
@connection = ConnectionMock.new(:nick => "DRUG-bot")
- @message = OpenStruct.new({ :command => :join, :channel => "#test", :nick => "DRUG-bot" })
- @file = File.expand_path('../support/responses/rubygems.response', __FILE__)
- EventMachine::MockHttpRequest.pass_through_requests = false
- EventMachine::MockHttpRequest.register_file('http://rubygems.org:80/api/v1/gems/latest.json', :get, @file)
+ @message = OpenStruct.new({ :command => :prvmsg, :channel => "#test", :nick => "DRUG-bot" })
+ @gem = File.expand_path('../support/responses/acts-as-messageable.response', __FILE__)
+ @gem2 = File.expand_path('../support/responses/acts-as-messageable2.response', __FILE__)
+ EventMachine::MockHttpRequest.pass_through_requests = true
+ EventMachine::MockHttpRequest.register_file('http://rubygems.org:80/api/v1/gems/acts-as-messageable.json', :get, @gem)
+ EventMachine::MockHttpRequest.register_file('http://rubygems.org:80/api/v1/gems/acts-as-messageable2.json', :get, @gem2)
EventMachine::MockHttpRequest.activate!
end
- it "should print last gem" do
- @rubygems.last_gem = "fake_gem"
+ after do
+ FileUtils.rm("#{ENV["HOME"]}/.muzang/muzang.rubygems")
+ end
+
+ it "should add gem to watching list" do
+ @message.message = "watch! acts-as-messageable"
EM.run do
@rubygems.call(@connection, @message)
- eventually(1) { @connection.message_count }
+ eventually(true, :times => 10) do
+ @connection.messages.include? "Dodalem gema acts-as-messageable do obserwowanych" and
+ @connection.messages.include? "Aktualna wersja: acts-as-messageable (0.4.2)"
+ end
end
end
- it "should not print last gem" do
- @rubygems.last_gem = "action_links"
+ it "should raise error" do
+ @message.message = "watch! acts-as-messageable2"
EM.run do
@rubygems.call(@connection, @message)
- eventually(0) { @connection.message_count }
+ eventually(true) do
+ @connection.messages.include? "Niepoprawna nazwa gema"
+ end
+ end
+ end
+
+ it "should not add gem twice to store" do
+ @message.message = "watch! acts-as-messageable"
+ EM.run do
+ 2.times{ @rubygems.call(@connection, @message) }
+ eventually(true) do
+ @connection.messages.include? "Gem acts-as-messageable jest juz obserwowany"
+ end
+ end
+ end
+
+ it "should notice about new version of gem" do
+ @message.message = ""
+ @message.command = :join
+
+ EM.run do
+ @rubygems.call(@connection, @message)
+ @message.message = "watch! acts-as-messageable"
+ @rubygems.call(@connection, @message)
+
+ @rubygems.store.transaction{ @rubygems.store[:gems]["acts-as-messageable"][:version] = "0.4.1" }
+
+ eventually(true, :every => 0.1, :total => 100) do
+ @connection.messages.include? "Nowa wersja acts-as-messageable (0.4.2)"
+ end
end
end
end