Skip to content
Browse files

Making the DSL a bit more compact

  • Loading branch information...
1 parent acd1e51 commit 22d72fd23f437d63bb568117bcdd40c9c4a01610 @qrush qrush committed Jul 14, 2009
View
33 features/manage_collaborators.feature
@@ -6,35 +6,40 @@ Feature: Manage collaborators
When I execute the following code
"""
Enforcer "thoughtbot", "deadbeef" do
- project "shoulda" do
- collaborators 'rmmt'
- end
+ project "shoulda", 'rmmt'
end
"""
- 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 "rmmt" as a collaborator for "shoulda"
+
+ Scenario: Adding a single collaborator for more than one project
+ When I execute the following code
+ """
+ Enforcer "thoughtbot", "deadbeef" do
+ project "shoulda", 'rmmt'
+ project "factory_girl", 'qrush'
+ end
+ """
+ Then the GitHub API should have received a request to add "rmmt" as a collaborator for "shoulda"
+ Then the GitHub API should have received a request to add "qrush" as a collaborator for "factory_girl"
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
+ project "shoulda", 'rmmt', 'coreyhaines', 'qrush'
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"
+ Then the GitHub API should have received a request to add "rmmt" as a collaborator for "shoulda"
+ And the GitHub API should have received a request to add "coreyhaines" as a collaborator for "shoulda"
+ And the GitHub API should have received a request to add "qrush" as a collaborator for "shoulda"
Scenario: Removing one collaborator from the project
Given "qrush" is a collaborator for "shoulda"
When I execute the following code
"""
Enforcer "thoughtbot", "deadbeef" do
- project "shoulda" do
- collaborators 'coreyhaines'
- end
+ project "shoulda", 'coreyhaines'
end
"""
- Then the GitHub API should have received a request to add a "coreyhaines" as a collaborator for "shoulda"
+ Then the GitHub API should have received a request to add "coreyhaines" as a collaborator for "shoulda"
And the GitHub API should have received a request to remove "qrush" as a collaborator for "shoulda"
View
2 features/step_definitions/enforcer_steps.rb
@@ -21,7 +21,7 @@
eval(code)
end
-Then /^the GitHub API should have received a request to add a "(.*)" as a collaborator for "(.*)"$/ do |user, repo|
+Then /^the GitHub API should have received a request to add "(.*)" as a collaborator for "(.*)"$/ do |user, repo|
assert_received(@repo) { |subject| subject.add(user) }
end
View
15 lib/enforcer.rb
@@ -12,26 +12,21 @@ def initialize(account_name, api_key)
@api_key = api_key
end
- def project(project_name, &block)
- instance_eval(&block)
- return if @collaborators.nil?
+ def project(project_name, *collaborators)
+ return if collaborators.nil?
STDOUT.puts "Enforcing settings for #{project_name}"
repo = Repository.new(@account_name, @api_key, project_name)
existing_collaborators = repo.list
- { :add => @collaborators - existing_collaborators,
- :remove => existing_collaborators - @collaborators}.each_pair do |action, collaborators|
- collaborators.each do |collaborator|
+ { :add => collaborators - existing_collaborators,
+ :remove => existing_collaborators - collaborators}.each_pair do |action, group|
+ group.each do |collaborator|
repo.send(action, collaborator)
end
end
end
-
- def collaborators(*names)
- @collaborators = names
- end
end
def Enforcer(account_name, api_key, &block)
View
23 test/enforcer_test.rb
@@ -17,19 +17,15 @@ class EnforcerTest < Test::Unit::TestCase
end
should "add a collaborator to the project" do
- @enforcer.project @project do
- collaborators 'chaines'
- end
+ @enforcer.project @project, 'chaines'
assert_received(@repo) do |subject|
subject.add('chaines')
end
end
should "add collaborators to the project" do
- @enforcer.project @project do
- collaborators 'chaines', 'qrush'
- end
+ @enforcer.project @project, 'chaines', 'qrush'
assert_received(@repo) do |subject|
subject.add('chaines')
@@ -45,19 +41,15 @@ class EnforcerTest < Test::Unit::TestCase
end
should "not add existing user to the project" do
- @enforcer.project @project do
- collaborators 'ralph'
- end
+ @enforcer.project @project, 'ralph'
assert_received(@repo) do |subject|
subject.add('ralph').never
end
end
should "remove existing user from the project if not in collaborators" do
- @enforcer.project @project do
- collaborators 'qrush'
- end
+ @enforcer.project @project, 'qrush'
assert_received(@repo) do |subject|
subject.add('qrush')
@@ -70,15 +62,16 @@ class EnforcerTest < Test::Unit::TestCase
context "setting up enforcer dsl" do
setup do
@enforcer = "enforcer"
- stub(@enforcer).project(anything)
+ stub(@enforcer).project(anything, anything)
@account = "thoughtbot"
@api_key = "api key"
mock(Enforcer).new(@account, @api_key) { @enforcer }
end
+
should "be there and take a string and block" do
- Enforcer(@account, @api_key) { project("corey") {} }
- assert_received(@enforcer) { |subject| subject.project("corey") }
+ Enforcer(@account, @api_key) { project("shoulda", "corey") {} }
+ assert_received(@enforcer) { |subject| subject.project("shoulda", "corey") }
end
end
end
View
4 test/integration.rb
@@ -5,7 +5,5 @@
token = `git config github.token`
Enforcer "qrush", token.chomp do
- project "jekyll" do
- collaborators "qrush"
- end
+ project "aquinas", "qrush", "mittens"
end

0 comments on commit 22d72fd

Please sign in to comment.
Something went wrong with that request. Please try again.