Permalink
Browse files

Bunch of work to get sudo working on a hackfest. This will be tossed

  • Loading branch information...
1 parent 5be7cb1 commit db6621b23ac750333c7cffd74b3da38655f8b094 Harold Giménez committed Jul 7, 2010
@@ -2,6 +2,10 @@ Feature: Disabling sudo with an environment variable
@creates_blog
Scenario: the sudo environment variable is not set
+ Given the following gems are not installed
+ | gem |
+ | nokogiri |
+ | RedCloth |
When I create a project called blog with SUDO set to true
Then the following commands should have been called with sudo
| command |
@@ -25,8 +25,11 @@
When /I create a project called (\w+) with SUDO set to (\w+)/ do |project_name, sudo|
bin_path = File.expand_path('../../bin', File.dirname(__FILE__))
- sudo_path = File.dirname(__FILE__) + '/support/bin'
- command = "PATH=#{sudo_path}:#{ENV['PATH']} SUDO=#{sudo} #{bin_path}/suspenders create #{project_name}"
+ sudo_path = File.expand_path('../support/bin', File.dirname(__FILE__))
+ command = "PATH=#{sudo_path}:#{ENV['PATH']} SUDO=#{sudo} #{bin_path}/suspenders create #{project_name} 2>&1"
+ puts "*"*80
+ puts "Running command:\n#{command}"
+ puts "*"*80
out = `#{command}`
fail "Creating project #{project_name} failed: #$?\n#{out}" if $? != 0
end
@@ -45,7 +48,13 @@
end
Then 'the following commands should have been called with sudo' do |table|
- contents = ''
- File.open('../../support/sudos_used', 'r') { |file| contents += file.gets }
+ contents = IO.read(File.expand_path('../support/sudos_used', File.dirname(__FILE__)))
contents.should include(row['command'])
end
+
+When 'the following gems are not installed' do |table|
+ table.hashes.each do |row|
+ SourceIndex.fake_uninstall_gem(row['gem'])
+ end
+end
+
View
1 features/support/bin/sudo 100644 → 100755
@@ -1,5 +1,6 @@
#!/usr/bin/env ruby
+puts "Running fake sudo with #{ARGV}"
File.open('../sudos_used', 'a+') do |file|
file.puts ARGV.join(' ')
end
View
@@ -8,4 +8,5 @@
FileUtils.rm_rf('blog')
sudos_file = '../support/sudos_used'
File.delete(sudos_file) if File.exists?(sudos_file)
+ SourceIndex.clear_installed_gems
end
View
@@ -1,11 +1,24 @@
module Gem
- def self.source_index
+ extend self
+ def source_index
SourceIndex.new
end
end
class SourceIndex
def find_name(gem_name)
- [gem_name]
+ @@installed_gems.select { |gem| gem == gem_name }
+ end
+
+ def self.fake_install_gem(gem_name)
+ (@@installed_gems ||= []) << gem_name
+ end
+
+ def self.fake_uninstall_gem(gem_name)
+ (@@installed_gems ||= []).delete(gem_name)
+ end
+
+ def self.clear_installed_gems
+ @@installed_gems = []
end
end
View
@@ -0,0 +1,7 @@
+gem install nokogiri --version=1.4.0
+gem install RedCloth --version=4.2.2
+gem install nokogiri --version=1.4.0
+gem install RedCloth --version=4.2.2
+gem install nokogiri --version=1.4.0
+gem install RedCloth --version=4.2.2
+gem install nokogiri --version=1.4.0

0 comments on commit db6621b

Please sign in to comment.