Skip to content

Commit

Permalink
Add configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
josepjaume committed Sep 24, 2011
1 parent 3ebbd99 commit 48617e6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 3 deletions.
11 changes: 8 additions & 3 deletions bin/spinach
Expand Up @@ -4,10 +4,15 @@ begin
require 'spinach'
rescue LoadError
require_relative '../lib/spinach'
require_relative '../examples/steps/user_logs_in.rb'
Dir.glob(
File.expand_path File.join(Spinach.config[:step_definitions_path], '**', '*.rb')
).each do |file|
require file
end
end

ARGV.each do |file|
parsed = Spinach::Parser.new(file).parse
Spinach::Runner.new.run(parsed)
Spinach::Runner.new(
Spinach::Parser.new(file).parse
).run
end
23 changes: 23 additions & 0 deletions examples/user_logs_in.rb
@@ -0,0 +1,23 @@
class UserLogsIn < Spinach::Feature
feature "User logs in"

Given 'I am not logged in' do
123
end

When 'I log in' do
@a = 'hey'
end

Then 'I should be logged in' do
user.must_equal 'heyo'
end

private

def user
@user ||= User.make
end

end

1 change: 1 addition & 0 deletions lib/spinach.rb
@@ -1,4 +1,5 @@
require_relative 'spinach/version'
require_relative 'spinach/config'
require_relative 'spinach/runner'
require_relative 'spinach/parser'
require_relative 'spinach/dsl'
Expand Down
17 changes: 17 additions & 0 deletions lib/spinach/config.rb
@@ -0,0 +1,17 @@
module Spinach
def self.config
@config ||= Config.new
end
class Config
attr_writer :step_definitions_path
def step_definitions_path
@step_definitions_path || 'features/steps'
end
def [](attribute)
self.send(attribute)
end
def []=(attribute, params)
self.send("#{attribute}=", params)
end
end
end
13 changes: 13 additions & 0 deletions test/spinach/config_test.rb
@@ -0,0 +1,13 @@
require_relative '../test_helper'

describe Spinach::Config do
describe "#step_definitions_path" do
it "returns a default" do
(Spinach.config[:step_definitions_path].kind_of? String).must_equal true
end
it "can be overwritten" do
Spinach.config[:step_definitions_path] = 'steps'
Spinach.config[:step_definitions_path].must_equal 'steps'
end
end
end

0 comments on commit 48617e6

Please sign in to comment.