Skip to content
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

Merged
merged 9 commits into from
Feb 14, 2015
Merged

migrate unit tests from test-unit to mini-test #256

merged 9 commits into from
Feb 14, 2015

Conversation

mroth
Copy link
Member

@mroth mroth commented Feb 12, 2015

mini-test has been the stdlib standard since ruby 1.9. since it functions on ruby 1.8.7 as well (and probably as far back as ruby 1.6 which we don't support), we might as well switch to it at some point prior to creating a bunch of unit tests when refactoring classes.

@mroth mroth added the refactor label Feb 12, 2015
@matthutchinson
Copy link
Member

👍 ++ on MiniTest for unit testing!

did nothing but test whether git gem was working as expected.  will
need a real unit test suite for our GitInfo class instead.
ruby-lint wants assert-match to be more specific
these should be gone once we do #99 and these will move into each
respective gem test suite
unfortunately aruba specifically uses rspec-assertions, which conflict
with the way cucumber loads minitest that it did not with testunit.

to get around this, i rewrote our steps that use assertions to use
rspec expectations.
@mroth
Copy link
Member Author

mroth commented Feb 12, 2015

This was relatively straightforward, with the exception of me banging my head against some weird incompatibilities between cucumber/aruba/minitest (see 6bc799a), but I think this is working now (pending CI approval)

@mroth
Copy link
Member Author

mroth commented Feb 12, 2015

BTW, current state of the world: we have a few unit tests that are actually for plugins (now in their own file), a single solitary unit test that is actually testing for a pre-build error condition but not validating our code, and zero current unit tests for actual lolcommits classes. 😲

(our cuke integration tests are nice though!)

@mroth
Copy link
Member Author

mroth commented Feb 13, 2015

Okay, not sure what's going on... The twitter existing plugin tests seem to randomly fail. Just rerunning repeatedly sometimes they work, sometimes they don't. (Sheesh, I will be so happy when plugins can be out of the codebase!)

@matthutchinson any idea what might be going on here?

@mroth
Copy link
Member Author

mroth commented Feb 13, 2015

Okay, better visibility into whats going on with change in 926cb3d.

  1) Failure:
PluginsTest#test_lol_twitter_build_tweet [test/plugins_test.rb:36]:
--- expected
+++ actual
@@ -1 +1 @@
-"Ex officia aut similique sed perspiciatis ut aperiam aspernatur nesciunt autem magni dolore sed saepe ... #lolcommits"
+"@prefixing! Ex officia aut similique sed perspiciatis ut aperiam aspernatur nesciunt autem magni dolor... #suffixing!"

Looks like the lolcommits plugin tests are actually order dependent (ugh), even though they certainly shouldn't be. Since minitest randomizes test order, when they execute out of order they have preserved state.

@mroth
Copy link
Member Author

mroth commented Feb 13, 2015

Okay, fixed for now via 918c845 by force defining configuration on each test.

The way the tests for the Twitter plugin are stubbing is really bad practice since it affects global state. It should be possible to restructure these tests to not do so if someone wants to take it on, but in my opinion this can hold us over until we get the plugins out of the main codebase entirely.

@@ -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)
Copy link
Member

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 😄

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@matthutchinson
Copy link
Member

Just caught up on your work here now, added a few comments, let me know what you think 💭

@matthutchinson
Copy link
Member

OK, overall a good start and good to merge I think 👍

mroth added a commit that referenced this pull request Feb 14, 2015
migrate unit tests from test-unit to mini-test
@mroth mroth merged commit fc37152 into master Feb 14, 2015
@mroth mroth deleted the minitest branch February 14, 2015 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants