Skip to content

Commit

Permalink
Avoid issues by declaring the constant name
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-hill committed Sep 8, 2023
1 parent bb9befe commit 56134ed
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions spec/cucumber/core/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
end

describe 'a generated event' do
before do
# Needed to be set this way because of a name inflection in the method
Object.const_set('MyEventType', Class.new(described_class.new(:foo, :bar)))
let(:my_event_type) do
Class.new(described_class.new(:foo, :bar)) do
# Anonymous classes don't respond to .name. So we override it!
def self.name
'Cucumber::Core::MyEventType'
end
end
end

it 'can be converted to a hash' do
expect(MyEventType.new(1, 2).to_h).to eq(foo: 1, bar: 2)
expect(my_event_type.new(1, 2).to_h).to eq(foo: 1, bar: 2)
end

it 'has an event_id' do
expect(MyEventType.event_id).to eq(:my_event_type)
expect(MyEventType.new(1, 2).event_id).to eq(:my_event_type)
expect(my_event_type.event_id).to eq(:my_event_type)
expect(my_event_type.new(1, 2).event_id).to eq(:my_event_type)
end
end
end

0 comments on commit 56134ed

Please sign in to comment.