Skip to content

Instantly share code, notes, and snippets.

@geku
Created July 1, 2013 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geku/5904674 to your computer and use it in GitHub Desktop.
Save geku/5904674 to your computer and use it in GitHub Desktop.
Q quick test to show how MiniTest let works. The let block is reevaluated for everytime, so it is basically the same as before but lazily evaluated whereas before is executed always even if none of the results are used for a test.
require 'rubygems'
require 'minitest/autorun'
describe 'let_test' do
let(:sub) {
puts " - lazy :sub called"
true
}
it("is empty") {
puts "=== call 1.1"
sub.must_equal true
puts "=== call 1.2"
sub.must_equal true
puts "=== call 1.3"
sub.must_equal true
}
it("is filled") {
puts "=== call 2.1"
sub.must_equal true
puts "=== call 2.2"
sub.must_equal true
puts "=== call 2.3"
sub.must_equal true
}
end
@geku
Copy link
Author

geku commented Jul 1, 2013

The result of ruby let_test.rb is:

$ ruby let_test.rb 
Run options: --seed 57795

# Running tests:

=== call 1.1
   - lazy :sub called
=== call 1.2
=== call 1.3
.=== call 2.1
   - lazy :sub called
=== call 2.2
=== call 2.3
.

Finished tests in 0.000939s, 2129.9255 tests/s, 6389.7764 assertions/s.

2 tests, 6 assertions, 0 failures, 0 errors, 0 skips

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment