basic os support

This commit is contained in:
John Bintz 2012-06-06 11:20:02 -04:00
parent 011c53b5eb
commit 34a7e04ed4
4 changed files with 55 additions and 0 deletions

View File

@ -129,3 +129,26 @@ Feature: Gemfiles
gem "one", {:path=>"../one"} gem "one", {:path=>"../one"}
""" """
@wip @mocha
Scenario: OS-specific blocks
Given I have the file "Gemfile.penchant" with the content:
"""
os :darwin do
gem 'one', :path => '../%s'
end
"""
And I am on the "darwin" platform
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
"""
# generated by penchant, environment: local
gem "one", {:path=>"../one"}
"""
Given I am on the "linux" platform
When I rebuild the Gemfile for "local" mode
Then the file "Gemfile" should have the following content:
"""
# generated by penchant, environment: local
"""

View File

@ -0,0 +1,3 @@
Given /^I am on the "([^"]*)" platform$/ do |os|
Penchant::Gemfile::PenchantFile.any_instance.stubs(:current_os).returns(os.to_sym)
end

View File

@ -1,14 +1,27 @@
require 'fakefs/safe' require 'fakefs/safe'
require 'penchant' require 'penchant'
require 'mocha'
World(Mocha::Standalone)
Before('@fakefs') do Before('@fakefs') do
FakeFS.activate! FakeFS.activate!
end end
Before('@mocha') do
mocha_setup
end
After do After do
FakeFS::FileSystem.clear FakeFS::FileSystem.clear
FakeFS.deactivate! FakeFS.deactivate!
begin
mocha_verify
ensure
mocha_teardown
end
FileUtils.rm_rf 'tmp' FileUtils.rm_rf 'tmp'
end end

View File

@ -112,6 +112,10 @@ module Penchant
yield if !is_deployment yield if !is_deployment
end end
def os(*args)
yield if args.include?(current_os)
end
protected protected
def args_to_string(args) def args_to_string(args)
args.inspect[1..-2] args.inspect[1..-2]
@ -144,6 +148,18 @@ module Penchant
}.sort }.sort
] ]
end end
def current_os
require 'rbconfig'
case host_os = RbConfig::CONFIG['host_os']
when /darwin/
:darwin
when /linux/
:linux
else
host_os[%r{^[a-z]+}, 1].to_sym
end
end
end end
class ERBFile < FileProcessor class ERBFile < FileProcessor