diff --git a/features/ruby_gemfile.feature b/features/ruby_gemfile.feature index f9391e8..ba5a032 100644 --- a/features/ruby_gemfile.feature +++ b/features/ruby_gemfile.feature @@ -129,3 +129,26 @@ Feature: Gemfiles 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 + + """ + diff --git a/features/step_definitions/given/i_am_on_the_linux_platform.rb b/features/step_definitions/given/i_am_on_the_linux_platform.rb new file mode 100644 index 0000000..c8bd68b --- /dev/null +++ b/features/step_definitions/given/i_am_on_the_linux_platform.rb @@ -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 diff --git a/features/support/env.rb b/features/support/env.rb index caee814..6f8f552 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,14 +1,27 @@ require 'fakefs/safe' require 'penchant' +require 'mocha' + +World(Mocha::Standalone) Before('@fakefs') do FakeFS.activate! end +Before('@mocha') do + mocha_setup +end + After do FakeFS::FileSystem.clear FakeFS.deactivate! + begin + mocha_verify + ensure + mocha_teardown + end + FileUtils.rm_rf 'tmp' end diff --git a/lib/penchant/gemfile.rb b/lib/penchant/gemfile.rb index 4e504f6..cba2c99 100644 --- a/lib/penchant/gemfile.rb +++ b/lib/penchant/gemfile.rb @@ -112,6 +112,10 @@ module Penchant yield if !is_deployment end + def os(*args) + yield if args.include?(current_os) + end + protected def args_to_string(args) args.inspect[1..-2] @@ -144,6 +148,18 @@ module Penchant }.sort ] 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 class ERBFile < FileProcessor