Class: RspecTestData::SeedsHelper
- Inherits:
-
Object
- Object
- RspecTestData::SeedsHelper
- Defined in:
- lib/rspec_test_data/seeds_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(spec_path) ⇒ SeedsHelper
constructor
A new instance of SeedsHelper.
- #load(test_data_class_name, **args) ⇒ Object
Constructor Details
#initialize(spec_path) ⇒ SeedsHelper
Returns a new instance of SeedsHelper.
11 12 13 |
# File 'lib/rspec_test_data/seeds_helper.rb', line 11 def initialize(spec_path) @spec_path = spec_path end |
Class Method Details
.for_rails ⇒ Object
7 8 9 |
# File 'lib/rspec_test_data/seeds_helper.rb', line 7 def self.for_rails self.new(Rails.root / "spec") end |
Instance Method Details
#load(test_data_class_name, **args) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rspec_test_data/seeds_helper.rb', line 15 def load(test_data_class_name,**args) if test_data_class_name !~ /^RspecTestData::/ test_data_class_name = "RspecTestData::#{test_data_class_name}" end parts = test_data_class_name.split(/::/).map(&:underscore) path = (@spec_path / parts[1..-1].join("/")).to_s + ".test_data.rb" if !File.exist?(path) raise "Expected to find test data for #{test_data_class_name} in '#{path}', but that file doesn't exist." end require_relative path test_data_class_name.constantize.new(**args) end |