File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed
lib/rails/generators/testing Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change
1
+ * Introduce ` Rails::Generators::Testing::Assertions#assert_initializer `
2
+
3
+ Compliments the existing ` initializer ` generator action.
4
+
5
+ ``` rb
6
+ assert_initializer " mail_interceptors.rb"
7
+ ```
8
+
9
+ * Steve Polito *
10
+
1
11
* Generate a .devcontainer folder and its contents when creating a new app.
2
12
3
13
The .devcontainer folder includes everything needed to boot the app and do development in a remote container.
Original file line number Diff line number Diff line change @@ -121,6 +121,26 @@ def assert_field_default_value(attribute_type, value)
121
121
assert_equal ( value , create_generated_attribute ( attribute_type ) . default )
122
122
end
123
123
end
124
+
125
+ # Asserts a given initializer exists. You need to supply a path relative
126
+ # to the `config/initializers/` directory.
127
+ #
128
+ # assert_initializer "mail_interceptors.rb"
129
+ #
130
+ # You can also give extra arguments. If the argument is a regexp, it will check if the
131
+ # regular expression matches the given file content. If it's a string, it compares the
132
+ # file with the given string:
133
+ #
134
+ # assert_initializer "mail_interceptors.rb", /SandboxEmailInterceptor/
135
+ #
136
+ # Finally, when a block is given, it yields the file content:
137
+ #
138
+ # assert_initializer "mail_interceptors.rb" do |initializer|
139
+ # assert_match(/SandboxEmailInterceptor/, initializer)
140
+ # end
141
+ def assert_initializer ( name , *contents )
142
+ assert_file ( "config/initializers/#{ name } " , *contents )
143
+ end
124
144
end
125
145
end
126
146
end
Original file line number Diff line number Diff line change @@ -401,7 +401,7 @@ def test_rakefile_should_write_date_to_file_with_block_in_lib_tasks
401
401
402
402
def test_initializer_should_write_date_to_file_in_config_initializers
403
403
action :initializer , "constants.rb" , "MY_CONSTANT = 42"
404
- assert_file "config/initializers/ constants.rb", "MY_CONSTANT = 42\n "
404
+ assert_initializer " constants.rb", "MY_CONSTANT = 42\n "
405
405
end
406
406
407
407
def test_initializer_should_write_date_to_file_with_block_in_config_initializers
@@ -411,7 +411,7 @@ def test_initializer_should_write_date_to_file_with_block_in_config_initializers
411
411
end
412
412
RUBY
413
413
action ( :initializer , "constants.rb" ) { code }
414
- assert_file "config/initializers/ constants.rb", code . strip_heredoc
414
+ assert_initializer " constants.rb", code . strip_heredoc
415
415
end
416
416
417
417
test "generate" do
You can’t perform that action at this time.
0 commit comments