Skip to content

Commit

Permalink
Merge pull request #256 from mroth/minitest
Browse files Browse the repository at this point in the history
migrate unit tests from test-unit to mini-test
  • Loading branch information
mroth committed Feb 14, 2015
2 parents 1f374ed + 918c845 commit fc37152
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ end
Rake::Task[:build].prerequisites.unshift :fix_permissions

Rake::TestTask.new do |t|
t.pattern = 'test/test_*.rb'
t.pattern = 'test/*_test.rb'
end

Rake::FileUtilsExt.verbose(false)
Expand Down
6 changes: 3 additions & 3 deletions features/step_definitions/lolcommits_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
end

Then /^I should be (prompted for|presented) "(.*?)"$/ do |_, prompt|
assert @stdout.read.to_s.include?(prompt)
expect(@stdout.read.to_s).to include(prompt)
end

When /^I enter "(.*?)" for "(.*?)"$/ do |input, field|
Expand All @@ -82,7 +82,7 @@
end

Then /^there should be (?:exactly|only) (.*?) (jpg|gif|pid)(?:s?) in "(.*?)"$/ do |n, type, folder|
assert_equal n.to_i, Dir["#{current_dir}/#{folder}/*.#{type}"].count
expect(n.to_i).to eq(Dir["#{current_dir}/#{folder}/*.#{type}"].count)
end

Then /^the output should contain a list of plugins$/ do
Expand Down Expand Up @@ -110,7 +110,7 @@

Then /^there should be (\d+) commit entries in the git log$/ do |n|
sleep 1 # let the file writing catch up
assert_equal n.to_i, `git shortlog | grep -E '^[ ]+\w+' | wc -l`.chomp.to_i
expect(n.to_i).to eq `git shortlog | grep -E '^[ ]+\w+' | wc -l`.chomp.to_i
end

Given /^I am using a "(.*?)" platform$/ do |platform_name|
Expand Down
2 changes: 0 additions & 2 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
require 'aruba/cucumber'
require 'methadone/cucumber'
require 'open3'
require 'test/unit/assertions'
include Test::Unit::Assertions
require 'ffaker'
require 'fileutils'

Expand Down
2 changes: 1 addition & 1 deletion lolcommits.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Gem::Specification.new do |s|
s.add_development_dependency('ffaker', '~> 1.25.0')
s.add_development_dependency('travis', '~> 1.7.4')
s.add_development_dependency('coveralls', '~> 0.7.2')
s.add_development_dependency('test-unit', '~> 3.0.7')
s.add_development_dependency('minitest', '~> 5.5.1')

if RUBY_VERSION >= '1.9.3'
s.add_development_dependency('rubocop', '~> 0.28')
Expand Down
49 changes: 3 additions & 46 deletions test/test_lolcommits.rb → test/lolcommits_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require 'coveralls'
Coveralls.wear!

require 'test/unit'
require 'ffaker'
require 'minitest/autorun'

# Loads lolcommits directly from the lib folder so don't have to create
# a gem before testing
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
Expand All @@ -12,50 +12,7 @@

include Lolcommits

class LolTest < Test::Unit::TestCase
def test_can_parse_git
assert_nothing_raised do
gi = GitInfo.new
assert_not_nil gi.message
assert_not_nil gi.sha
end
end

#
# issue #57, https://github.com/mroth/lolcommits/issues/57
#
def test_tranzlate
[['what the hell', '(WH|W)UT TEH HELL'], ['seriously wtf', 'SRSLEH WTF']].each do |normal, lol|
tranzlated = Lolcommits::Tranzlate.tranzlate(normal)
assert_match /^#{lol}/, tranzlated
end
end

#
# issue #136, https://github.com/mroth/lolcommits/issues/136
def test_lol_twitter_build_tweet
long_commit_message = Faker::Lorem.sentence(500)
plugin = Lolcommits::LolTwitter.new(nil)
max_tweet_size = 116
suffix = '... #lolcommits'

Lolcommits::LolTwitter.send(:define_method, :max_tweet_size, Proc.new { max_tweet_size })
assert_match "#{long_commit_message[0..(max_tweet_size - suffix.length)]}#{suffix}", plugin.build_tweet(long_commit_message)
end

def test_lol_twitter_prefix_suffix
plugin = Lolcommits::LolTwitter.new(nil)
Lolcommits::LolTwitter.send(:define_method, :max_tweet_size, Proc.new { 116 })
assert_match 'commit msg #lolcommits', plugin.build_tweet('commit msg')

plugin_config = {
'prefix' => '@prefixing!',
'suffix' => '#suffixing!'
}
Lolcommits::LolTwitter.send(:define_method, :configuration, Proc.new { plugin_config })
assert_match '@prefixing! commit msg #suffixing!', plugin.build_tweet('commit msg')
end

class LolTest < MiniTest::Test
#
# issue #53, https://github.com/mroth/lolcommits/issues/53
# this will test the permissions but only locally, important before building a gem package!
Expand Down
52 changes: 52 additions & 0 deletions test/plugins_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- encoding : utf-8 -*-
require 'coveralls'
Coveralls.wear!

require 'minitest/autorun'
require 'ffaker'

# Loads lolcommits directly from the lib folder so don't have to create
# a gem before testing
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'lolcommits'

include Lolcommits

class PluginsTest < MiniTest::Test
#
# issue #57, https://github.com/mroth/lolcommits/issues/57
#
def test_tranzlate
[['what the hell', '(WH|W)UT TEH HELL'], ['seriously wtf', 'SRSLEH WTF']].each do |normal, lol|
tranzlated = Lolcommits::Tranzlate.tranzlate(normal)
assert_match(/^#{lol}/, tranzlated)
end
end

#
# issue #136, https://github.com/mroth/lolcommits/issues/136
def test_lol_twitter_build_tweet
long_commit_message = Faker::Lorem.sentence(500)
plugin = Lolcommits::LolTwitter.new(nil)
max_tweet_size = 116
suffix = '... #lolcommits'

Lolcommits::LolTwitter.send(:define_method, :max_tweet_size, Proc.new { max_tweet_size })
Lolcommits::LolTwitter.send(:define_method, :configuration, Proc.new { {} })
assert_equal "#{long_commit_message[0..(max_tweet_size - suffix.length)]}#{suffix}", plugin.build_tweet(long_commit_message)
end

def test_lol_twitter_prefix_suffix
plugin = Lolcommits::LolTwitter.new(nil)
Lolcommits::LolTwitter.send(:define_method, :max_tweet_size, Proc.new { 116 })
assert_match 'commit msg #lolcommits', plugin.build_tweet('commit msg')

plugin_config = {
'prefix' => '@prefixing!',
'suffix' => '#suffixing!'
}
Lolcommits::LolTwitter.send(:define_method, :configuration, Proc.new { plugin_config })
assert_equal '@prefixing! commit msg #suffixing!', plugin.build_tweet('commit msg')
end
end

0 comments on commit fc37152

Please sign in to comment.