Permalink
Browse files

Get rid of use_steps. We can now just use modules instead!

  • Loading branch information...
1 parent a23f8c0 commit dfa7f4be809c919f7c2ae09802d2c46cb5b06412 @jnicklas committed Apr 24, 2012
Showing with 10 additions and 162 deletions.
  1. +0 −1 lib/turnip.rb
  2. +9 −1 lib/turnip/dsl.rb
  3. +0 −47 lib/turnip/step_module.rb
  4. +1 −7 spec/dsl_spec.rb
  5. +0 −106 spec/step_module_spec.rb
View
@@ -17,7 +17,6 @@ class Ambiguous < StandardError; end
autoload :Placeholder, 'turnip/placeholder'
autoload :Table, 'turnip/table'
autoload :StepLoader, 'turnip/step_loader'
- autoload :StepModule, 'turnip/step_module'
module Execute
def step(description, extra_arg=nil)
View
@@ -9,7 +9,15 @@ def step(description, &block)
end
def steps_for(tag, &block)
- Turnip::StepModule.steps_for(tag, &block)
+ if tag.to_s == "global"
+ warn "[Turnip] using steps_for(:global) is deprecated, add steps to Turnip::Steps instead"
+ Turnip::Steps.module_eval(&block)
+ else
+ mod = Module.new
+ mod.extend Turnip::Define
+ mod.module_eval(&block)
+ RSpec.configure { |c| c.include mod, tag => true }
+ end
end
end
end
View
@@ -1,47 +0,0 @@
-require 'pathname'
-
-module Turnip
- module StepModule
- module DSL
- def use_steps(*tags)
- Turnip::StepModule.modules_for(*tags).each do |mod|
- include mod
- end
- end
- end
-
- extend self
-
- def clear_module_registry
- module_registry.clear
- end
-
- def modules_for(*taggings)
- taggings.map do |tag|
- module_registry[tag]
- end.flatten.uniq
- end
-
- def module_registry
- @module_registry ||= Hash.new { |hash, key| hash[key] = [] }
- end
-
- def steps_for(tag, &block)
- anon = step_module(&block)
-
- module_registry[tag] << anon
-
- RSpec.configure do |config|
- config.include anon, tag => true
- end
- end
-
- def step_module(&block)
- anon = Module.new
- anon.extend(Turnip::Define)
- anon.extend(Turnip::StepModule::DSL)
- anon.module_eval(&block)
- anon
- end
- end
-end
View
@@ -1,16 +1,10 @@
require 'spec_helper'
describe Turnip::DSL do
- before do
- Turnip::StepModule.clear_module_registry
- end
-
let(:context) { stub.tap { |s| s.extend(Turnip::DSL) }}
describe '.steps_for' do
- it 'delegates to StepModule' do
- Turnip::StepModule.should_receive(:steps_for).with(:example)
- context.steps_for(:example) {}
+ pending 'adds the module to RSpec' do
end
end
View
@@ -1,106 +0,0 @@
-describe Turnip::StepModule do
- before(:each) do
- Turnip::StepModule.clear_module_registry
- end
-
- describe '.modules_for' do
- it 'returns the unique registered modules' do
- Turnip::StepModule.steps_for(:first) {}
- Turnip::StepModule.steps_for(:second) {}
- Turnip::StepModule.modules_for(:first, :second).size.should eq(2)
- end
-
- it 'returns the unique registered modules with use_steps' do
- Turnip::StepModule.steps_for(:first) {}
- Turnip::StepModule.steps_for(:second) { use_steps :first }
- Turnip::StepModule.steps_for(:third) { use_steps :first, :second }
- Turnip::StepModule.modules_for(:third).size.should eq(3)
- end
-
- it 'ignores a circular step dependency' do
- Turnip::StepModule.steps_for(:first) { use_steps :second }
- Turnip::StepModule.steps_for(:second) { use_steps :first }
- expect do
- Turnip::StepModule.modules_for(:second)
- end.should_not raise_error
- end
-
- it 'orders the step modules from use_steps before the using step module' do
- Turnip::StepModule.steps_for(:first) {}
- Turnip::StepModule.steps_for(:second) { use_steps :first }
- Turnip::StepModule.modules_for(:second).first.should == Turnip::StepModule.module_registry[:first].first.step_module
- Turnip::StepModule.modules_for(:second).last.should == Turnip::StepModule.module_registry[:second].first.step_module
- end
- end
-
- describe '.steps_for' do
- it 'registers the given tag' do
- Turnip::StepModule.steps_for(:first) {}
- Turnip::StepModule.should be_registered(:first)
- end
-
- it 'registers an anonymous modle for the given tags' do
- Turnip::StepModule.steps_for(:first) {}
- Turnip::StepModule.module_registry[:first].first.step_module.should be_instance_of(Module)
- end
-
- end
-
- describe '.step_module' do
- subject do
- Turnip::StepModule.step_module do
- def marker; end
- end
- end
-
- it 'extends the steps DSL' do
- subject.should be_kind_of(Turnip::StepModule::DSL)
- end
-
- it 'creates an anonymous module' do
- # Check for empty string to allow for rbx
- subject.name.should satisfy {|name| name.nil? || name.empty? }
- end
-
- it 'executes the block in the module' do
- # Map to sym to allow for rbx
- subject.instance_methods.map(&:to_sym).should include(:marker)
- end
- end
-
- describe Turnip::StepModule::DSL do
- describe '.step' do
- it 'registers the step for the module' do
- mod = Module.new do
- extend Turnip::StepModule::DSL
- step('example') { true }
- end
- mod.steps.first.expression.should eq('example')
- end
- end
-
- describe '.placeholder' do
- before { Turnip::Placeholder.send(:placeholders).clear }
-
- it 'registers the placeholder globally' do
- mod = Module.new do
- extend Turnip::StepModule::DSL
- placeholder('example') { true }
- end
- Turnip::Placeholder.send(:placeholders).should have_key('example')
- end
- end
-
- describe '.use_steps' do
- it "updates the list of used steps" do
- mod = Module.new do
- extend Turnip::StepModule::DSL
- step('example') { true }
-
- use_steps :other_steps
- end
- mod.uses_steps.should include(:other_steps)
- end
- end
- end
-end

0 comments on commit dfa7f4b

Please sign in to comment.