diff --git a/features/manage_collaborators.feature b/features/manage_collaborators.feature index 0b90dc4..e479147 100644 --- a/features/manage_collaborators.feature +++ b/features/manage_collaborators.feature @@ -3,10 +3,7 @@ Feature: Manage collaborators Given an account "thoughtbot" with an api key of "deadbeef" Scenario: Adding a single collaborator for a specific project - Given the following collaborators for "shoulda" - |name | - |thoughtbot| - Given I am adding "rmmt" as a collaborator to "shoulda" + When I execute the following code """ Enforcer "thoughtbot", "deadbeef" do project "shoulda" do @@ -14,6 +11,17 @@ Feature: Manage collaborators end end """ - When I execute it - Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda" + Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda" + Scenario: Adding more than one collaborators for a specific project + When I execute the following code + """ + Enforcer "thoughtbot", "deadbeef" do + project "shoulda" do + collaborators 'rmmt', 'coreyhaines', 'qrush' + end + end + """ + Then the GitHub API should have received a request to add a "rmmt" as a collaborator for "shoulda" + And the GitHub API should have received a request to add a "coreyhaines" as a collaborator for "shoulda" + And the GitHub API should have received a request to add a "qrush" as a collaborator for "shoulda" diff --git a/features/step_definitions/enforcer_steps.rb b/features/step_definitions/enforcer_steps.rb index c2cdb6f..db42012 100644 --- a/features/step_definitions/enforcer_steps.rb +++ b/features/step_definitions/enforcer_steps.rb @@ -1,27 +1,27 @@ +Before do + stub(GitHubApi).add_collaborator(anything, anything, anything, anything) +end + + Given /^an account "(.*)" with an api key of "(.*)"$/ do |account, api_key| @account = account @api_key = api_key end -Given /^I am adding "(.*)" as a collaborator to "(.*)"$/ do |user, repo, code| - @names << user - @names_list = @names.join('", "') - @collaborators = '{"collaborators: + ["' + @names_list + '"]}' +# Given /^I am adding "(.*)" as a collaborator to "(.*)"$/ do |user, repo, code| +# @names = [] +# @names << user +# @names_list = @names.join('", "') +# @collaborators = '{"collaborators: + ["' + @names_list + '"]}' +# +# mock(GitHubApi).add_collaborator(@account, @api_key, repo, user) +# @code = code +# end - mock(GitHubApi).add_collaborator(@account, @api_key, repo, user) - @code = code +When /^I execute the following code$/ do |code| + eval(code) end -When /^I execute it$/ do - eval(@code) -end - -Given /^the following collaborators for "([^\"]*)"$/ do |project_name, table| - @names = [] - table.hashes.each do |collaborator| - @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(@account, @api_key, repo, user) } diff --git a/features/support/env.rb b/features/support/env.rb index 2553743..6bb2a9d 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -8,3 +8,16 @@ World(Test::Unit::Assertions) World(RR::Adapters::TestUnit) + +Before do + RR.reset +end + +After do + begin + RR.verify + ensure + RR.reset + end +end + diff --git a/test/enforcer_test.rb b/test/enforcer_test.rb index 9def854..a9016d9 100644 --- a/test/enforcer_test.rb +++ b/test/enforcer_test.rb @@ -9,7 +9,7 @@ class EnforcerTest < Test::Unit::TestCase @enforcer = Enforcer.new(@username, @api_key) end - should "add collaborators to the project" do + should "add a collaborator to the project" do @enforcer.project 'foo' do collaborators 'chaines' end @@ -18,6 +18,17 @@ class EnforcerTest < Test::Unit::TestCase subject.add_collaborator(@username, @api_key, 'foo', 'chaines') end end + + should "add collaborators to the project" do + @enforcer.project 'foo' do + collaborators 'chaines', 'qrush' + end + + assert_received(GitHubApi) do |subject| + subject.add_collaborator(@username, @api_key, 'foo', 'chaines') + subject.add_collaborator(@username, @api_key, 'foo', 'qrush') + end + end end context "setting up enforcer dsl" do