Class: Test::Unit::TestCase
- Inherits:
-
Object
- Object
- Test::Unit::TestCase
- Defined in:
- lib/mocked_fixtures/testcase.rb
Class Method Summary collapse
- .all_fixture_table_names ⇒ Object
- .global_mock_fixtures=(*table_names) ⇒ Object
- .mock_fixtures(*table_names) ⇒ Object
- .mock_fixtures_with(mock_framework) ⇒ Object
-
.setup_mock_fixture_accessors(table_names = nil) ⇒ Object
This creates the fixture accessors and retrieves the fixture and creates mock object from it.
Instance Method Summary collapse
- #setup_with_mock_fixtures ⇒ Object (also: #setup_with_fixtures)
Class Method Details
.all_fixture_table_names ⇒ Object
41 42 43 44 |
# File 'lib/mocked_fixtures/testcase.rb', line 41 def self.all_fixture_table_names table_names = Dir["#{fixture_path}/*.yml"] + Dir["#{fixture_path}/*.csv"] table_names.map { |f| File.basename(f).split('.')[0..-2].join('.') } end |
.global_mock_fixtures=(*table_names) ⇒ Object
17 18 19 20 |
# File 'lib/mocked_fixtures/testcase.rb', line 17 def self.global_mock_fixtures=(*table_names) table_names = self.all_fixture_table_names if table_names.first == :all self.mock_fixtures table_names.flatten.map { |n| n.to_s } end |
.mock_fixtures(*table_names) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mocked_fixtures/testcase.rb', line 30 def self.mock_fixtures(*table_names) table_names = self.all_fixture_table_names if table_names.first == :all table_names = table_names.flatten.map { |n| n.to_s } self.mock_fixture_table_names |= table_names require_fixture_classes(table_names) setup_mock_fixture_accessors(table_names) end |
.mock_fixtures_with(mock_framework) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/mocked_fixtures/testcase.rb', line 22 def self.mock_fixtures_with(mock_framework) require "mocked_fixtures/mocks/#{mock_framework}" self.mocked_fixtures_mock_framework = mock_framework unless mock_framework == :rspec self.send(:alias_method, :mock_model, "mock_model_with_#{mock_framework}".to_sym) end end |
.setup_mock_fixture_accessors(table_names = nil) ⇒ Object
This creates the fixture accessors and retrieves the fixture and creates mock object from it. Mock fixture is then cached.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mocked_fixtures/testcase.rb', line 48 def self.setup_mock_fixture_accessors(table_names = nil) (table_names || mock_fixture_table_names).each do |table_name| table_name = table_name.to_s.tr('.', '_') class_eval " def mock_\#{table_name}(*fixtures, &block)\n create_mock_fixtures('\#{table_name}', *fixtures, &block)\n end\n END\n end\nend\n" |
Instance Method Details
#setup_with_mock_fixtures ⇒ Object Also known as: setup_with_fixtures
60 61 62 63 64 |
# File 'lib/mocked_fixtures/testcase.rb', line 60 def setup_with_mock_fixtures fixtures_to_load = self.class.mock_fixture_table_names - self.class.loaded_mock_fixtures.keys load_mock_fixtures(fixtures_to_load) unless fixtures_to_load.empty? setup_without_mock_fixtures end |