Skip to content

Commit 1d3f6cc

Browse files
committed
fix using load in command files
1 parent d809a59 commit 1d3f6cc

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [Unreleased]
2+
3+
### Fixed
4+
* fix using `load` in command files
5+
16
## [1.9.0]
27
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.8.1...v1.9.0
38

lib/cypress_on_rails/command_executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module CypressOnRails
44
# loads and evals the command files
55
class CommandExecutor
6-
def self.load(file,command_options = nil)
6+
def self.perform(file,command_options = nil)
77
load_cypress_helper
88
file_data = File.read(file)
99
eval file_data, binding, file

lib/cypress_on_rails/middleware.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def handle_command(req)
5656
missing_command = commands.find {|command| !@file.exists?(command.file_path) }
5757

5858
if missing_command.nil?
59-
results = commands.map { |command| @command_executor.load(command.file_path, command.options) }
59+
results = commands.map { |command| @command_executor.perform(command.file_path, command.options) }
6060

6161
begin
6262
output = results.to_json

spec/cypress_on_rails/command_executor_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'cypress_on_rails/command_executor'
22

33
RSpec.describe CypressOnRails::CommandExecutor do
4-
describe '.load' do
4+
describe '.perform' do
55
let(:folder) { "#{__dir__}/command_executor" }
66
subject { described_class }
77

8-
def executor_load(*values)
9-
subject.load(*values)
8+
def executor_perform(*values)
9+
subject.perform(*values)
1010
end
1111

1212
before do
@@ -15,18 +15,18 @@ def executor_load(*values)
1515
end
1616

1717
it 'runs test command' do
18-
executor_load("#{folder}/test_command.rb")
18+
executor_perform("#{folder}/test_command.rb")
1919
expect(DummyTest.values).to eq(%w(hello))
2020
end
2121

2222
it 'runs test command twice' do
23-
executor_load("#{folder}/test_command.rb")
24-
executor_load("#{folder}/test_command.rb")
23+
executor_perform("#{folder}/test_command.rb")
24+
executor_perform("#{folder}/test_command.rb")
2525
expect(DummyTest.values).to eq(%w(hello hello))
2626
end
2727

2828
it 'runs command with options' do
29-
executor_load("#{folder}/test_command_with_options.rb", 'my_string')
29+
executor_perform("#{folder}/test_command_with_options.rb", 'my_string')
3030
expect(DummyTest.values).to eq(%w(my_string))
3131
end
3232
end

spec/cypress_on_rails/middleware_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ def rack_input(json_value)
1616

1717
context '/__cypress__/command' do
1818
before do
19-
allow(command_executor).to receive(:load).and_return({ id: 1, title: 'some result' })
19+
allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
2020
allow(file).to receive(:exists?)
2121
env['PATH_INFO'] = '/__cypress__/command'
2222
end
2323

2424
it 'command file exists' do
25-
allow(command_executor).to receive(:load).and_return({ id: 1, title: 'some result' })
25+
allow(command_executor).to receive(:perform).and_return({ id: 1, title: 'some result' })
2626
env['rack.input'] = rack_input(name: 'seed')
2727
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
2828

2929
aggregate_failures do
3030
expect(response).to eq([201,
3131
{"Content-Type"=>"application/json"},
3232
["[{\"id\":1,\"title\":\"some result\"}]"]])
33-
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
33+
expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', nil)
3434
end
3535
end
3636

@@ -42,21 +42,21 @@ def rack_input(json_value)
4242
expect(response).to eq([201,
4343
{"Content-Type"=>"application/json"},
4444
["[{\"id\":1,\"title\":\"some result\"}]"]])
45-
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', ['my_options'])
45+
expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', ['my_options'])
4646
end
4747
end
4848

4949
it 'command file does not exists' do
5050
object = BasicObject.new
51-
allow(command_executor).to receive(:load).and_return(object)
51+
allow(command_executor).to receive(:perform).and_return(object)
5252
env['rack.input'] = rack_input(name: 'seed')
5353
allow(file).to receive(:exists?).with('spec/cypress/app_commands/seed.rb').and_return(true)
5454

5555
aggregate_failures do
5656
expect(response).to eq([201,
5757
{"Content-Type"=>"application/json"},
5858
["{\"message\":\"Cannot convert to json\"}"]])
59-
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
59+
expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', nil)
6060
end
6161
end
6262

@@ -68,7 +68,7 @@ def rack_input(json_value)
6868
expect(response).to eq([201,
6969
{"Content-Type"=>"application/json"},
7070
["[{\"id\":1,\"title\":\"some result\"}]"]])
71-
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/seed.rb', nil)
71+
expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/seed.rb', nil)
7272
end
7373
end
7474

@@ -82,8 +82,8 @@ def rack_input(json_value)
8282
expect(response).to eq([201,
8383
{"Content-Type"=>"application/json"},
8484
["[{\"id\":1,\"title\":\"some result\"},{\"id\":1,\"title\":\"some result\"}]"]])
85-
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_user.rb', nil)
86-
expect(command_executor).to have_received(:load).with('spec/cypress/app_commands/load_sample.rb', {'all' => 'true'})
85+
expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/load_user.rb', nil)
86+
expect(command_executor).to have_received(:perform).with('spec/cypress/app_commands/load_sample.rb', {'all' => 'true'})
8787
end
8888
end
8989

@@ -94,7 +94,7 @@ def rack_input(json_value)
9494

9595
aggregate_failures do
9696
expect(response).to eq([404, {}, ['could not find command file: spec/cypress/app_commands/load_sample.rb']])
97-
expect(command_executor).to_not have_received(:load)
97+
expect(command_executor).to_not have_received(:perform)
9898
end
9999
end
100100
end

0 commit comments

Comments
 (0)