instance method assert_initializer

Ruby on Rails 8.1.2

Since v7.2.3

Available in: v7.2.3 v8.0.4 v8.1.2

Signature

assert_initializer(name, *contents, &block)

Asserts a given initializer exists. You need to supply a path relative to the config/initializers/ directory.

assert_initializer "mail_interceptors.rb"

You can also give extra arguments. If the argument is a regexp, it will check if the regular expression matches the given file content. If it’s a string, it compares the file with the given string:

assert_initializer "mail_interceptors.rb", /SandboxEmailInterceptor/

Finally, when a block is given, it yields the file content:

assert_initializer "mail_interceptors.rb" do |initializer|
  assert_match(/SandboxEmailInterceptor/, initializer)
end

Parameters

name req
contents rest
block block
Source
# File railties/lib/rails/generators/testing/assertions.rb, line 141
        def assert_initializer(name, *contents, &block)
          assert_file("config/initializers/#{name}", *contents, &block)
        end

Defined in railties/lib/rails/generators/testing/assertions.rb line 141 · View on GitHub · Improve this page · Find usages on GitHub

Defined in Rails::Generators::Testing::Assertions

Type at least 2 characters to search.

↑↓ navigate · open · esc close