Sha256: 46c5b91f962d158c87e738ab8446b533796e78a1026b3e524c818c3607623462

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

# frozen_string_literal: true
require 'test_helper'

class NameErrorHandlingTest < ActionDispatch::IntegrationTest
  setup do
    aamine = Author.create! name: 'aamine'
    @rhg = aamine.books.create! title: 'RHG'
  end

  test 'raising NameError in a decorator' do
    err = assert_raises ActionView::Template::Error do
      visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}/errata"
    end

    assert_match(/undefined method `poof!' for/, err.message)
    assert_match 'poof!', err.cause.name if err.respond_to?(:cause)
  end

  test "Don't touch NameError that was not raised from a decorator module but from other classes" do
    err = assert_raises ActionView::Template::Error do
      visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}/errata2"
    end

    assert_match(/undefined method `boom!' for/, err.message)
    assert_match 'boom!', err.cause.name if err.respond_to?(:cause)
    assert_not_match(/active_decorator\/lib\/active_decorator\/.* in method_missing'$/, err.backtrace[0])
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_decorator-1.0.0 test/features/name_error_handling_test.rb