Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

127 lines (107 sloc) 4.019 kB
require File.expand_path('../helper', __FILE__)
class CampfireTest < Service::TestCase
class MockCampfire
class Room
attr_reader :name, :lines
def initialize(name)
@name = name
@lines = []
end
def speak(line)
@lines << line
end
end
attr_reader :rooms
def initialize(subd, options = {})
@subdomain = subd
@rooms = []
@options = options
@token = options[:token]
end
attr_reader :subdomain, :token
def find_room_by_name(name)
@rooms << (r=Room.new(name))
r
end
end
def test_push
svc = service({"token" => "t", "subdomain" => "s", "room" => "r"}, payload)
svc.receive_push
assert_equal 1, svc.campfire.rooms.size
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
assert_equal 'r', svc.campfire.rooms.first.name
assert_equal 4, svc.campfire.rooms.first.lines.size # 3 + summary
assert svc.campfire.rooms.first.lines.first.match(/short/)
end
def test_issues
svc = service(:issues, {"token" => "t", "subdomain" => "s", "room" => "r"}, issues_payload)
svc.receive_issues
assert_equal 1, svc.campfire.rooms.size
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
assert_equal 'r', svc.campfire.rooms.first.name
assert_equal 1, svc.campfire.rooms.first.lines.size # 3 + summary
assert_match /\[grit\] defunkt opened issue #5: booya./i, svc.campfire.rooms.first.lines.first
end
def test_pull
svc = service(:pull_request, {"token" => "t", "subdomain" => "s", "room" => "r"}, pull_payload)
svc.receive_pull_request
assert_equal 1, svc.campfire.rooms.size
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
assert_equal 'r', svc.campfire.rooms.first.name
assert_equal 1, svc.campfire.rooms.first.lines.size # 3 + summary
assert_match /\[grit\] defunkt opened pull request #5: booya \(master...feature\)/i, svc.campfire.rooms.first.lines.first
end
def test_full_domain
svc = service({"token" => "t", "subdomain" => "s.campfirenow.com", "room" => "r"}, payload)
svc.receive_push
assert_equal 1, svc.campfire.rooms.size
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
assert_equal 'r', svc.campfire.rooms.first.name
assert_equal 4, svc.campfire.rooms.first.lines.size # 3 + summary
assert svc.campfire.rooms.first.lines.first.match(/short/)
end
def test_long_url
svc = service({"token" => "t", "subdomain" => "s", "room" => "r", "long_url" => "1"}, payload)
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
svc.receive_push
assert svc.campfire.rooms.first.lines.first.match(/github\.com/), "Summary url should not be shortened"
end
def test_push_non_master_with_master_only
non_master_payload = payload
non_master_payload["ref"] = "refs/heads/non-master"
svc = service({"token" => "t", "subdomain" => "s", "room" => "r", "master_only" => 1}, non_master_payload)
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
svc.receive_push
assert_equal 0, svc.campfire.rooms.size
end
def test_push_non_master_without_master_only
non_master_payload = payload
non_master_payload["ref"] = "refs/heads/non-master"
svc = service({"token" => "t", "subdomain" => "s", "room" => "r", "master_only" => 0}, non_master_payload)
assert_equal 's', svc.campfire.subdomain
assert_equal 't', svc.campfire.token
svc.receive_push
assert_equal 4, svc.campfire.rooms.first.lines.size # 3 + summary
end
def setup
Service::Campfire.campfire_class = MockCampfire
end
def teardown
Service::Campfire.campfire_class = Tinder::Campfire
end
def service(*args)
svc = super(Service::Campfire, *args)
class << svc
def shorten_url(*args)
'short'
end
end
svc
end
end
Jump to Line
Something went wrong with that request. Please try again.