Permalink
Browse files

Plenty of confusion since either fakeweb or github is being a pain

Signed-off-by: Nick Quaranto <nick@quaran.to>
  • Loading branch information...
1 parent 0860dbe commit 4aeb4b3a491a40ecc8e8f6a52cea16e696938adb @coreyhaines coreyhaines committed with qrush Jul 13, 2009
@@ -1,16 +1,17 @@
Feature: Manage collaborators
- Background:
- Given we are capturing http requests
-
Scenario: Adding a single collaborator for a specific project
- Given the following
+ Given the following collaborators for "shoulda"
+ |name |
+ |thoughtbot|
+ Given I am adding "rmmt" as a collaborator to "shoulda"
"""
- project "shoulda" do
- collaborators 'rmmt'
+ Enforcer "thoughtbot" do
+ project "shoulda" do
+ collaborators 'rmmt'
+ end
end
"""
When I execute it
- Then I should have made a request to add the collaborators to project "shoulda"
- |name|
- |rmmt|
+ Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda"
+
@@ -1,19 +1,25 @@
-Given /^we are capturing http requests$/ do
- stub(GitHubApi).add_collaborator(anything, anything)
-end
+Given /^I am adding "(.*)" as a collaborator to "(.*)"$/ do |user, repo, code|
+ @names << user
+ @names_list = @names.join('", "')
+ @collaborators = '{"collaborators: + ["' + @names_list + '"]}'
-Given /^the following$/ do |code|
+ mock(GitHubApi).add_collaborator(repo, user)
+# FakeWeb.register_uri(:post, "http://github.com/api/v2/json/repos/collaborators/#{@repo}/#{@user}", :string => @collaborators)
@code = code
end
When /^I execute it$/ do
- enforcer = Enforcer.new
- enforcer.instance_eval(@code)
+ eval(@code)
end
-Then /^I should have made a request to add the collaborators to project "(.*)"$/ do |project_name, table|
+Given /^the following collaborators for "([^\"]*)"$/ do |project_name, table|
+ @names = []
table.hashes.each do |collaborator|
- assert_received(GitHubApi) { |subject| subject.add_collaborator(project_name, collaborator[:name]) }
+ @names << collaborator[:name]
end
end
+Then /^the GitHub API should have received a request to add a "(.*)" as a collaborator for "(.*)"$/ do |user, repo|
+ assert_received(GitHubApi) { |subject| subject.add_collaborator(repo, user) }
+end
+
View
@@ -2,6 +2,9 @@
require 'rr'
require 'test/unit'
require 'enforcer'
+require 'fakeweb'
+
+FakeWeb.allow_net_connect = false
World(Test::Unit::Assertions)
World(RR::Adapters::TestUnit)
View
@@ -1,6 +1,9 @@
+$:.unshift(File.dirname(__FILE__))
require 'github_api'
class Enforcer
+ def initialize(user_name)
+ end
def project(project_name, &block)
instance_eval(&block)
@@ -15,3 +18,8 @@ def collaborators(*names)
@collaborators = names
end
end
+
+def Enforcer(user_name, &block)
+ enforcer = Enforcer.new(user_name)
+ enforcer.instance_eval(&block)
+end
View
@@ -1,2 +1,5 @@
class GitHubApi
+ def self.add_collaborator(repo, collaborator)
+ ["qrush", collaborator]
+ end
end
View
@@ -4,9 +4,14 @@ class EnforcerTest < Test::Unit::TestCase
context "with an enforcer" do
setup do
stub(GitHubApi).add_collaborator(anything, anything)
- @enforcer = Enforcer.new
+ @username = "user"
+ @enforcer = Enforcer.new(@username)
end
+ #should "store username" do
+ #assert_equal @username, @enforcer.username
+ #end
+
should "adds the collaborators to the project" do
@enforcer.project 'foo' do
collaborators 'chaines'
@@ -17,4 +22,18 @@ class EnforcerTest < Test::Unit::TestCase
end
end
end
+
+ context "setting up enforcer dsl" do
+ setup do
+ @enforcer = "enforcer"
+ stub(@enforcer).project(anything)
+
+ @username = "thoughtbot"
+ mock(Enforcer).new(@username) { @enforcer }
+ end
+ should "be there and take a string and block" do
+ Enforcer("thoughtbot") { project("corey") {} }
+ assert_received(@enforcer) { |subject| subject.project("corey") }
+ end
+ end
end
View
@@ -1,10 +1,21 @@
require 'test_helper'
class GitHubApiTest < Test::Unit::TestCase
- context "existence" do
- should "exist" do
- assert GitHubApi
+
+ context "adding collaborators" do
+ setup do
+ @repo = "repo"
+ @user = "coreyhaines" + rand(10).to_s
+ @collaborators = '{"collaborators": ["qrush", "'+ @user +'"]}'
+# FakeWeb.register_uri(:post, "http://github.com/api/v2/json/repos/collaborators/#{@repo}/#{@user}", :string => @collaborators)
+# stub(GitHubApi).post(
+ end
+
+ should "hit the github api" do
+ collaborators = GitHubApi.add_collaborator(@repo, @user)
+ assert_equal ["qrush",@user], collaborators
end
end
+
end
View
@@ -1,17 +1,18 @@
require 'rubygems'
require 'test/unit'
require 'shoulda'
+require 'rr'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'enforcer'
-require 'rr'
begin
require 'redgreen'
rescue LoadError
end
+
class Test::Unit::TestCase
include RR::Adapters::TestUnit
end

0 comments on commit 4aeb4b3

Please sign in to comment.