Skip to content
Browse files

Making binding work and figuring out more of the DSL

Signed-off-by: Nick Quaranto <nick@quaran.to>
  • Loading branch information...
1 parent 2861d65 commit 493248eafa07e858beb2d83fb24fd0f32e68b4a2 @coreyhaines coreyhaines committed with qrush
Showing with 39 additions and 4 deletions.
  1. +2 −1 features/step_definitions/enforcer_steps.rb
  2. +3 −3 features/support/env.rb
  3. +16 −0 lib/enforcer.rb
  4. +16 −0 test/enforcer_test.rb
  5. +2 −0 test/test_helper.rb
View
3 features/step_definitions/enforcer_steps.rb
@@ -7,7 +7,8 @@
end
When /^I execute it$/ do
- eval(@code)
+ enforcer = Enforcer.new
+ enforcer.instance_eval(@code)
end
Then /^I should have made a request to add the collaborators$/ do |table|
View
6 features/support/env.rb
@@ -1,7 +1,7 @@
require 'fileutils'
require 'rr'
require 'test/unit'
+require 'enforcer'
-World do
- include Test::Unit::Assertions
-end
+World(Test::Unit::Assertions)
+World(RR::Adapters::TestUnit)
View
16 lib/enforcer.rb
@@ -1 +1,17 @@
require 'github_api'
+
+class Enforcer
+
+ def project(project_name, &block)
+ instance_eval(&block)
+ return if @collaborators.nil?
+
+ @collaborators.each do |collaborator|
+ GitHubApi.add_collaborator(project_name, collaborator)
+ end
+ end
+
+ def collaborators(*names)
+ @collaborators = names
+ end
+end
View
16 test/enforcer_test.rb
@@ -1,4 +1,20 @@
require 'test_helper'
class EnforcerTest < Test::Unit::TestCase
+ context "with an enforcer" do
+ setup do
+ stub(GitHubApi).add_collaborator(anything, anything)
+ @enforcer = Enforcer.new
+ end
+
+ should "adds the collaborators to the project" do
+ @enforcer.project 'foo' do
+ collaborators 'chaines'
+ end
+
+ assert_received(GitHubApi) do |subject|
+ subject.add_collaborator('foo', 'chaines')
+ end
+ end
+ end
end
View
2 test/test_helper.rb
@@ -5,6 +5,7 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'enforcer'
+require 'rr'
begin
require 'redgreen'
@@ -12,4 +13,5 @@
end
class Test::Unit::TestCase
+ include RR::Adapters::TestUnit
end

0 comments on commit 493248e

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