bundler-bouncer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE.txt +8 -0
- data/Rakefile +57 -0
- data/Readme.md +0 -0
- data/lib/bundler/bouncer.rb +9 -0
- data/lib/bundler/bouncer/messages.rb +8 -0
- data/spec/bundler-bouncer_spec.rb +29 -0
- data/spec/mock_projects/dummy_gem-1.0.0.gem +0 -0
- data/spec/mock_projects/with_bundler/Gemfile +1 -0
- data/spec/mock_projects/with_bundler/Gemfile.lock +13 -0
- data/spec/mock_projects/with_bundler/app.rb +2 -0
- data/spec/mock_projects/without_bundler/app.rb +2 -0
- data/spec/spec_helper.rb +97 -0
- metadata +86 -0
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Copyright (c) 2011 Joshua Cheek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
8
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rubygems/package_task"
|
3
|
+
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
require "rspec"
|
8
|
+
task :spec do
|
9
|
+
sh 'rspec --format documentation --colour spec/*_spec.rb'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
# This builds the actual gem. For details of what all these options
|
14
|
+
# mean, and other ones you can add, check the documentation here:
|
15
|
+
#
|
16
|
+
# http://rubygems.org/read/chapter/20
|
17
|
+
#
|
18
|
+
spec = Gem::Specification.new do |s|
|
19
|
+
s.name = "bundler-bouncer"
|
20
|
+
s.version = File.read 'Version.txt'
|
21
|
+
s.summary = "Exits app if you forgot to run under bundle exec"
|
22
|
+
s.author = "Joshua Cheek"
|
23
|
+
s.email = "josh.cheek@gmail.com"
|
24
|
+
s.homepage = "https://github.com/JoshCheek/bundler-bouncer"
|
25
|
+
s.has_rdoc = false
|
26
|
+
s.files = %w(MIT-LICENSE.txt Rakefile Readme.md) + Dir.glob("{spec,lib}/**/*")
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
s.add_development_dependency "rspec", "~> 2.6.0"
|
29
|
+
s.add_development_dependency "bundler", "~> 1.0.15"
|
30
|
+
end
|
31
|
+
|
32
|
+
# This task actually builds the gem. We also regenerate a static
|
33
|
+
# .gemspec file, which is useful if something (i.e. GitHub) will
|
34
|
+
# be automatically building a gem for this project. If you're not
|
35
|
+
# using GitHub, edit as appropriate.
|
36
|
+
#
|
37
|
+
# To publish your gem online, install the 'gemcutter' gem; Read more
|
38
|
+
# about that here: http://gemcutter.org/pages/gem_docs
|
39
|
+
Gem::PackageTask.new(spec) do |pkg|
|
40
|
+
pkg.gem_spec = spec
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Build the gemspec file #{spec.name}.gemspec"
|
44
|
+
task :gemspec do
|
45
|
+
File.open "#{spec.name}.gemspec", "w" do |f|
|
46
|
+
f << spec.to_ruby
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# If you don't want to generate the .gemspec file, just remove this line. Reasons
|
51
|
+
# why you might want to generate a gemspec:
|
52
|
+
# - using bundler with a git source
|
53
|
+
# - building the gem without rake (i.e. gem build blah.gemspec)
|
54
|
+
# - maybe others?
|
55
|
+
task :package => :gemspec
|
56
|
+
|
57
|
+
|
data/Readme.md
ADDED
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "#{File.dirname __FILE__}/spec_helper"
|
2
|
+
describe 'bundler-bouncer' do
|
3
|
+
|
4
|
+
context 'from a file invoked with `bundle exec`' do
|
5
|
+
subject { run_app 'with_bundler', :bundler => true }
|
6
|
+
its(:exitstatus) { should be_zero }
|
7
|
+
its(:stderr) { should == '' }
|
8
|
+
its(:stdout) { should == '' }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'from a file invoked without `bundle exec`' do
|
12
|
+
context 'with USE_BUNDLER set to no' do
|
13
|
+
subject { run_app 'without_bundler', :bundler => false, :USE_BUNDLER => 'no' }
|
14
|
+
its(:exitstatus) { should == 0 }
|
15
|
+
its(:stdout) { should == '' }
|
16
|
+
its(:stderr) { should == bouncer_message(:turned_off) }
|
17
|
+
its(:stderr) { should be_coloured :yellow }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with USE_BUNDLER set to force' do
|
21
|
+
subject { run_app 'without_bundler', :bundler => false, :USE_BUNDLER => 'force' }
|
22
|
+
its(:exitstatus) { should == 1 }
|
23
|
+
its(:stdout) { should == '' }
|
24
|
+
its(:stderr) { should == bouncer_message(:missing_bundler) }
|
25
|
+
its(:stderr) { should be_coloured :red }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
gem "bundler-bouncer", :path => "/Users/josh/code/bundler-bouncer"
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
RSpec::Matchers.define :be_coloured do |colour|
|
2
|
+
|
3
|
+
string = nil
|
4
|
+
colours = {
|
5
|
+
:red => "\e[31m",
|
6
|
+
:yellow => "\e[33m",
|
7
|
+
:none => "\e[0m",
|
8
|
+
}
|
9
|
+
|
10
|
+
match do |_string|
|
11
|
+
string = _string
|
12
|
+
string.end_with?(colours[:none]) && string.start_with?(colours[colour])
|
13
|
+
end
|
14
|
+
|
15
|
+
failure_message_for_should do
|
16
|
+
"expected #{string.inspect} to be red (begin with #{colours[colour].inspect}, end with #{colours[:none].inspect})"
|
17
|
+
end
|
18
|
+
|
19
|
+
description do
|
20
|
+
"be #{colour}"
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def rootdir
|
28
|
+
File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def bouncer_message(message)
|
33
|
+
require "bundler/bouncer/messages"
|
34
|
+
Bundler::Bouncer::Messages[message]
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def use_bundler_env(val='force', &block)
|
39
|
+
crnt_val = ENV['USE_BUNDLER']
|
40
|
+
ENV['USE_BUNDLER'] = val
|
41
|
+
block.call
|
42
|
+
ensure
|
43
|
+
ENV['USE_BUNDLER'] = crnt_val
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def app_command(options)
|
48
|
+
command = ''
|
49
|
+
command << 'bundle exec ' if options[:bundler]
|
50
|
+
command << 'ruby '
|
51
|
+
command << "-I #{rootdir}/lib " unless options[:bundler]
|
52
|
+
command << 'app.rb'
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
class InvokedApp < Struct.new(:exitstatus, :stdout, :stderr)
|
57
|
+
require 'open3'
|
58
|
+
def self.invoke(command)
|
59
|
+
Open3.popen3 command do |stdin, stdout, stderr, wait_thr|
|
60
|
+
self.new(wait_thr.value.exitstatus, stdout.read.strip, stderr.read.strip)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def run_app(dir, options)
|
67
|
+
Dir.chdir "#{File.dirname __FILE__}/mock_projects/#{dir}" do
|
68
|
+
use_bundler_env options[:USE_BUNDLER] do
|
69
|
+
InvokedApp.invoke app_command(options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
def initialize_mock_projects
|
76
|
+
return if @mock_projects_initialized
|
77
|
+
@mock_projects_initialized = true
|
78
|
+
|
79
|
+
require 'fileutils'
|
80
|
+
|
81
|
+
# build the gem
|
82
|
+
results = `rake gemspec`
|
83
|
+
raise "Could not build gemspec: #{results}" unless $?.exitstatus.zero?
|
84
|
+
|
85
|
+
# make the Gemfile
|
86
|
+
File.open "#{rootdir}/spec/mock_projects/with_bundler/Gemfile", 'w' do |file|
|
87
|
+
file.puts %Q[gem "bundler-bouncer", :path => "#{rootdir}"]
|
88
|
+
end
|
89
|
+
|
90
|
+
# install the gems
|
91
|
+
Dir.chdir "#{rootdir}/spec/mock_projects/with_bundler" do
|
92
|
+
result = `bundle install`
|
93
|
+
raise "Could not install bundle: #{result}" unless $?.exitstatus.zero?
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
initialize_mock_projects
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bundler-bouncer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joshua Cheek
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-20 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 2.6.0
|
24
|
+
type: :development
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.15
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
description:
|
38
|
+
email: josh.cheek@gmail.com
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
files:
|
46
|
+
- MIT-LICENSE.txt
|
47
|
+
- Rakefile
|
48
|
+
- Readme.md
|
49
|
+
- spec/bundler-bouncer_spec.rb
|
50
|
+
- spec/mock_projects/dummy_gem-1.0.0.gem
|
51
|
+
- spec/mock_projects/with_bundler/app.rb
|
52
|
+
- spec/mock_projects/with_bundler/Gemfile
|
53
|
+
- spec/mock_projects/with_bundler/Gemfile.lock
|
54
|
+
- spec/mock_projects/without_bundler/app.rb
|
55
|
+
- spec/spec_helper.rb
|
56
|
+
- lib/bundler/bouncer/messages.rb
|
57
|
+
- lib/bundler/bouncer.rb
|
58
|
+
homepage: https://github.com/JoshCheek/bundler-bouncer
|
59
|
+
licenses: []
|
60
|
+
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.8.5
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: Exits app if you forgot to run under bundle exec
|
85
|
+
test_files: []
|
86
|
+
|