Method: Rails::Generators::Testing::Assertions#assert_instance_method

Defined in:
railties/lib/rails/generators/testing/assertions.rb

#assert_instance_method(method, content) {|$3.strip| ... } ⇒ Object Also known as: assert_method

Asserts the given method exists in the given content. When a block is given, it yields the content of the method.

assert_file "app/controllers/products_controller.rb" do |controller|
  assert_instance_method :index, controller do |index|
    assert_match(/Product\.all/, index)
  end
end

Yields:

  • ($3.strip)
[View source]

98
99
100
101
# File 'railties/lib/rails/generators/testing/assertions.rb', line 98

def assert_instance_method(method, content)
  assert content =~ /(\s+)def #{method}(\(.+\))?(.*?)\n\1end/m, "Expected to have method #{method}"
  yield $3.strip if block_given?
end