-
Notifications
You must be signed in to change notification settings - Fork 241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
migrate unit tests from test-unit to mini-test #256
Changes from all commits
50f55e0
5970558
97c577b
7ad88e8
1c2e4bb
6bc799a
5b7ac96
926cb3d
918c845
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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')) | ||
|
@@ -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 | ||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 its probably Ok to drop this test, I'd like to think most of the features would fail if GitInfo couldn't be read... |
||
# issue #53, https://github.com/mroth/lolcommits/issues/53 | ||
# this will test the permissions but only locally, important before building a gem package! | ||
|
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' | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we should add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe! I messed around with trying to use the built in stub functionality in minitest, but couldn't get it to work in this case right off. If you want to take a stab at it feel free to push directly to this branch/PR. That said I think these tests may benefit from being better written in a different way entirely anyhow once we extract to gem plugins. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats true, these tests will sit outside the main gem in the end, lets punt on this for now. |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we stick with the assert syntax in this file? Given we're using that style in the refactored plugin tests in this PR? Personally I prefer the assert MiniTest style over the 'expect to' grammar but this is just mho 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I would have preferred that, but there is an 3-way incompatibility with minitest/cucumber/aruba because aruba depends on rspec-expectations (see 6bc799a), and none of the workarounds functioned in our case that I could get to work. Thankfully it's only for the few assertions in the cuke tests. From looking through the issues boards it sounds like this may be addressed by the next major version of cucumber.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I think I see why.. this is so we can remove the dependency on TestUnit assertions within step definitions? And use the rspec-expectations available through aruba..
It kinda sucks a bit that rspec leaks in here tho. I wonder if Aruba can work with MiniTest like assertions somehow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, exactly. In theory we should be able to mixin MiniTest assertions the same way (although it requires a bit of boilerplate: https://github.com/cucumber/cucumber/wiki/Using-MiniTest) but that doesn't actually function if rspec functions are also loaded due to E_TOOMUCHMAGIC of different frameworks trying to do the right thing automatically.
That said even if it did work it introduces a larger amount of boilerplate than the 3-4 one line assertions.
I think its unlikely to be able to strip rspec-expectations out of Aruba, I think it uses a lot of its advanced functionality to write its ruleset. It may be possible to rewrite them all with minitest 5, which would be a pretty epic pull request for Aruba, but I suspect it would be quite an endeavor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍