Last active
September 18, 2018 03:35
-
-
Save courtenay/7343845 to your computer and use it in GitHub Desktop.
Revisions
-
courtenay renamed this gist
Nov 6, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
courtenay revised this gist
Nov 6, 2013 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -47,7 +47,14 @@ class ApiTest < MiniTest::Test @test = 5 end def test_fixtures assert_equal @test, 5 @test = 6 # let's see if it leaks end def test_fixtures_again assert_equal @test, 5 @test = 7 end end -
courtenay revised this gist
Nov 6, 2013 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -21,11 +21,16 @@ end # module TestRunner def before_setup # todo: start transaction here super self.class.fixtures.each do |key, val| instance_variable_set "#{key}", val end end def before_teardown # todo: rollback transaction here super end end # Then include it into your test -
courtenay revised this gist
Nov 6, 2013 . No changes.There are no files selected for viewing
-
courtenay created this gist
Nov 6, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ module Fixtures # # Set up fixtures that will be defined once during startup # and (perhaps) rolled back at the beginning of each test run # def fixtures &block if block_given? instance_eval &block @fixtures = {} (instance_variables - [:@fixtures]).each do |fresh| @fixtures[fresh] = instance_variable_get(fresh) end else @fixtures end end end # Before each test, look at the class-variables defined # and just tragically set them in the instance # module TestRunner def before_setup super self.class.fixtures.each do |key, val| instance_variable_set "#{key}", val end end end # Then include it into your test class MiniTest::Test extend Fixtures include TestRunner end # And define your test require 'minitest/autorun' class ApiTest < MiniTest::Test fixtures do @test = 5 end def test_fixtures_work assert_equal @test, 5 end end