Skip to content

Commit a528503

Browse files
committed
[rb] fix improperly nested class
1 parent 2fd9d1a commit a528503

3 files changed

Lines changed: 45 additions & 40 deletions

File tree

rb/lib/selenium/webdriver/common/interactions/key_input.rb

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@
2020
module Selenium
2121
module WebDriver
2222
module Interactions
23+
class TypingInteraction < Interaction
24+
attr_reader :type
25+
26+
def initialize(source, type, key)
27+
super(source)
28+
@type = assert_type(type)
29+
@key = Keys.encode_key(key)
30+
end
31+
32+
def assert_type(type)
33+
raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
34+
35+
KeyInput::SUBTYPES[type]
36+
end
37+
38+
def encode
39+
{type: @type, value: @key}
40+
end
41+
end # TypingInteraction
42+
2343
class KeyInput < InputDevice
2444
SUBTYPES = {down: :keyDown, up: :keyUp, pause: :pause}.freeze
2545

@@ -41,25 +61,8 @@ def create_key_up(key)
4161
add_action(TypingInteraction.new(self, :up, key))
4262
end
4363

44-
class TypingInteraction < Interaction
45-
attr_reader :type
46-
47-
def initialize(source, type, key)
48-
super(source)
49-
@type = assert_type(type)
50-
@key = Keys.encode_key(key)
51-
end
52-
53-
def assert_type(type)
54-
raise TypeError, "#{type.inspect} is not a valid key subtype" unless KeyInput::SUBTYPES.key? type
55-
56-
KeyInput::SUBTYPES[type]
57-
end
58-
59-
def encode
60-
{type: @type, value: @key}
61-
end
62-
end # TypingInteraction
64+
# Backward compatibility in case anyone called this directly
65+
class TypingInteraction < Interactions::TypingInteraction; end
6366
end # KeyInput
6467
end # Interactions
6568
end # WebDriver

rb/spec/unit/selenium/webdriver/common/interactions/input_device_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def type
8383
end
8484

8585
describe '#no_actions?' do
86-
let(:typing) { instance_double(KeyInput::TypingInteraction, type: :not_pause) }
86+
let(:typing) { instance_double(TypingInteraction, type: :not_pause) }
8787

8888
it 'returns true when all actions are pauses' do
8989
allow(device).to receive(:type).and_return(:none)
@@ -93,7 +93,7 @@ def type
9393

9494
it 'returns false when not all actions are pauses' do
9595
allow(device).to receive(:type).and_return(:none)
96-
allow(typing).to receive(:class).and_return(KeyInput::TypingInteraction)
96+
allow(typing).to receive(:class).and_return(TypingInteraction)
9797
device.create_pause
9898
device.add_action(typing)
9999
expect(device.no_actions?).to be false

rb/spec/unit/selenium/webdriver/common/interactions/key_input_spec.rb

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module Interactions
2525
describe KeyInput do
2626
let(:key_input) { KeyInput.new(:name) }
2727
let(:key) { 'a' }
28-
let(:interaction) { KeyInput::TypingInteraction.new(key_input, :up, 'a') }
28+
let(:interaction) { TypingInteraction.new(key_input, :up, 'a') }
2929

3030
describe '#type' do
3131
it 'returns :key' do
@@ -56,7 +56,7 @@ module Interactions
5656

5757
describe '#create_key_down' do
5858
it 'executes #add_action with created interaction' do
59-
allow(KeyInput::TypingInteraction).to receive(:new).with(key_input, :down, key).and_return(interaction)
59+
allow(TypingInteraction).to receive(:new).with(key_input, :down, key).and_return(interaction)
6060
allow(key_input).to receive(:add_action).and_call_original
6161

6262
key_input.create_key_down(key)
@@ -67,35 +67,37 @@ module Interactions
6767

6868
describe '#create_key_up' do
6969
it 'executes #add_action with created interaction' do
70-
allow(KeyInput::TypingInteraction).to receive(:new).with(key_input, :up, key).and_return(interaction)
70+
allow(TypingInteraction).to receive(:new).with(key_input, :up, key).and_return(interaction)
7171
allow(key_input).to receive(:add_action).and_call_original
7272

7373
key_input.create_key_up(key)
7474

7575
expect(key_input).to have_received(:add_action).with(interaction)
7676
end
7777
end
78+
end # KeyInput
7879

79-
describe 'KeyInput::TypingInteraction' do
80-
let(:source) { Interactions.key('keyboard') }
81-
let(:type) { :down }
82-
let(:typing) { KeyInput::TypingInteraction.new(source, type, key) }
80+
describe TypingInteraction do
81+
let(:source) { Interactions.key('keyboard') }
82+
let(:type) { :down }
83+
let(:typing) { TypingInteraction.new(source, type, key) }
84+
let(:key) { 'a' }
8385

84-
it 'stores type as KeyInput::SUBTYPES' do
85-
expect(typing.type).to eq KeyInput::SUBTYPES[type]
86-
end
86+
it 'stores type as KeyInput::SUBTYPES' do
87+
expect(typing.type).to eq KeyInput::SUBTYPES[type]
88+
end
8789

88-
it 'raises a TypeError if the passed type is not a key in KeyInput::SUBTYPES' do
89-
expect { KeyInput::TypingInteraction.new(source, :none, key) }.to raise_error(TypeError)
90-
end
90+
it 'raises a TypeError if the passed type is not a key in KeyInput::SUBTYPES' do
91+
expect { TypingInteraction.new(source, :none, key) }.to raise_error(TypeError)
92+
end
9193

92-
describe '#encode' do
93-
it 'returns a Hash with type and value' do
94-
expect(typing.encode).to eq(type: typing.type, value: key)
95-
end
94+
describe '#encode' do
95+
it 'returns a Hash with type and value' do
96+
expect(typing.encode).to eq(type: typing.type, value: key)
9697
end
97-
end # KeyInput::TypingInteraction
98-
end # KeyInput
98+
end
99+
end # TypingInteraction
100+
99101
end # Interactions
100102
end # WebDriver
101103
end # Selenium

0 commit comments

Comments
 (0)