Skip to content

Commit af674bd

Browse files
author
Sven Fuchs
committed
fix tests for running on ci
1 parent 60aaa2f commit af674bd

File tree

8 files changed

+63
-24
lines changed

8 files changed

+63
-24
lines changed

.bundle/config

-2
This file was deleted.

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
*.gem
1+
*.gem
2+
.bundle

Gemfile

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
source 'http://gemcutter.org'
1+
source :rubygems
2+
gemspec
23

3-
group :test do
4-
gem 'test_declarative'
5-
gem 'mocha'
6-
end

Gemfile.lock

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
PATH
2+
remote: .
3+
specs:
4+
gem-release (0.0.14)
5+
6+
GEM
7+
remote: http://rubygems.org/
8+
specs:
9+
mocha (0.9.8)
10+
rake
11+
rake (0.8.7)
12+
test_declarative (0.0.4)
13+
14+
PLATFORMS
15+
ruby
16+
17+
DEPENDENCIES
18+
gem-release!
19+
mocha (>= 0.9.8)
20+
test_declarative (>= 0.0.2)

lib/gem_release/gemspec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ class Gemspec < Template
55
def initialize(options = {})
66
super
77

8-
@authors ||= [`git config --get user.name`.strip]
9-
@email ||= `git config --get user.email`.strip
8+
@authors ||= [user_name]
9+
@email ||= user_email
1010
@homepage ||= "http://github.com/#{github_user}/#{name}" || "[your github name]"
1111

1212
@summary ||= '[summary]'

lib/gem_release/helpers.rb

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
module GemRelease
44
module Helpers
5+
def user_name
6+
`git config --get user.name`.strip
7+
end
8+
9+
def user_email
10+
`git config --get user.email`.strip
11+
end
12+
513
def github_user
614
@github_user ||= `git config --get github.user`.strip
715
end

test/gemspec_test.rb

+20-12
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,32 @@
66
class GemspecTest < Test::Unit::TestCase
77
include Gem::Commands
88

9+
def setup
10+
build_sandbox
11+
stub_exec(GemRelease::Gemspec,
12+
'git config --get user.name' => 'John Doe',
13+
'git config --get user.email' => '[email protected]',
14+
'git config --get github.user' => 'johndoe'
15+
)
16+
end
17+
18+
def teardown
19+
teardown_sandbox
20+
end
21+
922
test 'scaffolds a gemspec with default values' do
1023
source = GemRelease::Gemspec.new.render
1124
gemspec = eval(source)
1225

13-
user = %x[git config --get user.name].strip
14-
email = %x[git config --get user.email].strip
15-
github_user = %x[git config --get github.user].strip
16-
17-
assert_equal 'gem-release', gemspec.name
18-
assert_equal GemRelease::VERSION, gemspec.version.to_s
19-
# will work with local git config
20-
assert_equal [user], gemspec.authors
21-
assert_equal email, gemspec.email
22-
assert_equal "http://github.com/#{github_user}/gem-release", gemspec.homepage
26+
assert_equal 'foo-bar', gemspec.name
27+
assert_equal '0.0.1', gemspec.version.to_s
28+
assert_equal ['John Doe'], gemspec.authors
29+
assert_equal '[email protected]', gemspec.email
30+
assert_equal "http://github.com/johndoe/foo-bar", gemspec.homepage
2331
assert_equal '[summary]', gemspec.summary
2432
assert_equal '[description]', gemspec.description
2533

26-
assert_match %r(require 'gem_release/version'), source
34+
assert_match %r(require 'foo_bar/version'), source
2735
assert_match %r(files\s*=\s*Dir.glob\(\"lib\/\*\*\/\*\*\"\)), source
2836
end
2937

@@ -40,7 +48,7 @@ class GemspecTest < Test::Unit::TestCase
4048
end
4149

4250
test 'filename' do
43-
assert_equal 'gem-release.gemspec', GemRelease::Gemspec.new.filename
51+
assert_equal 'foo-bar.gemspec', GemRelease::Gemspec.new.filename
4452
end
4553

4654
end

test/test_helper.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
require 'rubygems_plugin'
55

66
require 'test/unit'
7-
require 'test_declarative'
8-
require 'mocha'
97
require 'ruby-debug'
108
require 'fileutils'
9+
require 'bundler/setup'
10+
require 'test_declarative'
11+
require 'mocha'
1112

1213
class Test::Unit::TestCase
1314
include Gem::Commands
@@ -23,6 +24,12 @@ def teardown_sandbox
2324
FileUtils.rm_r('tmp')
2425
end
2526

27+
def stub_exec(klass, commands)
28+
commands.each do |command, result|
29+
klass.any_instance.stubs(:`).with(command).returns(result)
30+
end
31+
end
32+
2633
def stub_command(command_class, *methods)
2734
command = command_class.new
2835
methods.each { |method| command.stubs(method) }

0 commit comments

Comments
 (0)