Class: AwsRecord::Generators::GeneratorTestHelper
- Inherits:
-
Object
- Object
- AwsRecord::Generators::GeneratorTestHelper
- Includes:
- FileUtils, Minitest::Assertions, Rails::Generators::Testing::Assertions, Rails::Generators::Testing::Behaviour
- Defined in:
- lib/generators/test_helper.rb
Instance Attribute Summary collapse
-
#assertions ⇒ Object
Returns the value of attribute assertions.
Instance Method Summary collapse
- #assert_file_fixture(generated_file, actual_file) ⇒ Object
- #assert_model_rand_table_name(generated_file, actual_file, table_name) ⇒ Object
- #cleanup ⇒ Object
-
#initialize(klass, dest) ⇒ GeneratorTestHelper
constructor
A new instance of GeneratorTestHelper.
- #run_generator(args = default_arguments, config = {}) ⇒ Object
- #run_in_test_app(cmd) ⇒ Object
Constructor Details
#initialize(klass, dest) ⇒ GeneratorTestHelper
Returns a new instance of GeneratorTestHelper.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/test_helper.rb', line 30 def initialize(klass, dest) @temp_root = File.(dest) GeneratorTestHelper.tests klass temp_app_dest = File.join(File.(@temp_root, __dir__), "test_app") GeneratorTestHelper.destination temp_app_dest destination_root_is_set? prepare_destination setup_test_app ensure_current_path self.assertions = 0 end |
Instance Attribute Details
#assertions ⇒ Object
Returns the value of attribute assertions.
24 25 26 |
# File 'lib/generators/test_helper.rb', line 24 def assertions @assertions end |
Instance Method Details
#assert_file_fixture(generated_file, actual_file) ⇒ Object
52 53 54 55 56 |
# File 'lib/generators/test_helper.rb', line 52 def assert_file_fixture(generated_file, actual_file) assert File.exist?(generated_file), "Expected file #{generated_file.inspect} to exist, but does not" assert File.exist?(actual_file), "Expected file #{actual_file.inspect} to exist, but does not" assert identical? generated_file, actual_file end |
#assert_model_rand_table_name(generated_file, actual_file, table_name) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/generators/test_helper.rb', line 58 def assert_model_rand_table_name(generated_file, actual_file, table_name) assert File.exist?(generated_file), "Expected file #{generated_file.inspect} to exist, but does not" assert File.exist?(actual_file), "Expected file #{actual_file.inspect} to exist, but does not" fixture = File.read(actual_file) generated = File.read(generated_file) fixture = fixture.gsub(/#table_name#/, table_name) assert fixture == generated end |
#cleanup ⇒ Object
69 70 71 |
# File 'lib/generators/test_helper.rb', line 69 def cleanup rm_rf @temp_root end |
#run_generator(args = default_arguments, config = {}) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/generators/test_helper.rb', line 73 def run_generator(args = default_arguments, config = {}) result = nil capture(:stderr) do result = super end result end |
#run_in_test_app(cmd) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/generators/test_helper.rb', line 45 def run_in_test_app(cmd) cd destination_root a = `rails #{cmd}` ensure_current_path end |