Skip to content

Instantly share code, notes, and snippets.

@senny
Last active August 29, 2015 14:15
Show Gist options
  • Save senny/c8cad80acf0f124151ae to your computer and use it in GitHub Desktop.
Save senny/c8cad80acf0f124151ae to your computer and use it in GitHub Desktop.
diff --git a/test/fixtures/high_scores.yml b/test/fixtures/high_scores.yml
index 0c3721e..9d3b342 100644
--- a/test/fixtures/high_scores.yml
+++ b/test/fixtures/high_scores.yml
@@ -1,5 +1,7 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
+<% require Rails.root + "test/support/fixture_helper" %>
+
one:
game: MyString
score: 1
diff --git a/test/support/fixture_helper.rb b/test/support/fixture_helper.rb
new file mode 100644
index 0000000..d689400
--- /dev/null
+++ b/test/support/fixture_helper.rb
@@ -0,0 +1,7 @@
+module TestFixtureHelper
+ def helper_test(number)
+ number
+ end
+end
+
+ActiveRecord::FixtureSet.context_class.send :include, TestFixtureHelper
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 81a09d4..92e39b2 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -7,12 +7,4 @@ class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
-
- module TestFixtureHelper
- def helper_test(number)
- number
- end
- end
-
- ActiveRecord::FixtureSet.context_class.send :include, TestFixtureHelper
end
diff --git a/Rakefile b/Rakefile
index ba6b733..0b20965 100644
--- a/Rakefile
+++ b/Rakefile
@@ -4,3 +4,7 @@
require File.expand_path('../config/application', __FILE__)
Rails.application.load_tasks
+
+task :environment do
+ require File.expand_path("../test/support/fixture_helper", __FILE__)
+end
diff --git a/test/support/fixture_helper.rb b/test/support/fixture_helper.rb
new file mode 100644
index 0000000..b7b5b7a
--- /dev/null
+++ b/test/support/fixture_helper.rb
@@ -0,0 +1,10 @@
+module TestFixtureHelper
+ def helper_test(number)
+ number
+ end
+end
+
+ActiveSupport.on_load(:active_record) do
+ require "active_record/fixtures"
+ ActiveRecord::FixtureSet.context_class.send :include, TestFixtureHelper
+end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 81a09d4..92e39b2 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -7,12 +7,4 @@ class ActiveSupport::TestCase
fixtures :all
# Add more helper methods to be used by all tests here...
-
- module TestFixtureHelper
- def helper_test(number)
- number
- end
- end
-
- ActiveRecord::FixtureSet.context_class.send :include, TestFixtureHelper
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment