-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Standardize testing helper methods (#215)
* Merge all support testing helpers for feature tests * Make sure to delete files on each tests * Pass a pipe as an input for retest process
- Loading branch information
Showing
68 changed files
with
794 additions
and
631 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
%w[ | ||
ruby-app | ||
ruby-bare | ||
git-ruby | ||
hanami-app | ||
rails-app | ||
rspec-rails | ||
rspec-ruby | ||
bundler-app | ||
].each do |folder| | ||
`cp -R ./features/support ./features/#{folder}/retest` | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
require 'securerandom' | ||
|
||
class OutputFile | ||
attr_reader :id | ||
|
||
attr_reader :output | ||
def initialize | ||
@id = SecureRandom.hex(10) | ||
create_file | ||
@output = Tempfile.new | ||
end | ||
|
||
def path | ||
"tmp/output-#{id}.log" | ||
@output.path | ||
end | ||
alias :to_s :path | ||
|
||
def read | ||
return unless File.exist?(path) | ||
|
||
File.read(path).split('[H[J').last | ||
@output.rewind | ||
@output.read.split('[H[J').last | ||
end | ||
|
||
def delete | ||
return unless File.exist?(path) | ||
|
||
File.delete(path) | ||
@output.close | ||
@output.unlink | ||
end | ||
alias :clear :delete | ||
|
||
private | ||
|
||
def create_file | ||
Dir.mkdir('tmp') unless Dir.exist?('tmp') | ||
File.open(path, "w") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
require_relative 'output_file' | ||
|
||
module FileHelper | ||
def default_sleep_seconds | ||
Float(ENV.fetch('DEFAULT_SLEEP_SECONDS', 1)) | ||
end | ||
|
||
def launch_sleep_seconds | ||
Float(ENV.fetch('LAUNCH_SLEEP_SECONDS', 1.5)) | ||
end | ||
|
||
def wait(sleep_seconds: default_sleep_seconds) | ||
sleep sleep_seconds | ||
end | ||
|
||
def modify_file(path, sleep_seconds: default_sleep_seconds) | ||
return unless File.exist? path | ||
|
||
old_content = File.read(path) | ||
File.open(path, 'w') { |file| file.write old_content } | ||
|
||
sleep sleep_seconds | ||
end | ||
|
||
def create_file(path, should_sleep: true, sleep_seconds: default_sleep_seconds) | ||
File.open(path, "w").tap(&:close) | ||
|
||
sleep sleep_seconds if should_sleep | ||
end | ||
|
||
def delete_file(path) | ||
return unless File.exist? path | ||
|
||
File.delete path | ||
end | ||
|
||
def rename_file(path, new_path) | ||
return unless File.exist? path | ||
|
||
File.rename path, new_path | ||
end | ||
end | ||
|
||
def launch_retest(command, sleep_seconds: launch_sleep_seconds) | ||
@rd, @input = IO.pipe | ||
@output = OutputFile.new | ||
@pid = Process.spawn command, out: @output.path, in: @rd | ||
sleep sleep_seconds | ||
end | ||
|
||
def end_retest(file = nil, pid = nil) | ||
@output&.delete | ||
@rd&.close | ||
@input&.close | ||
if @pid | ||
Process.kill('SIGHUP', @pid) | ||
Process.detach(@pid) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
require 'securerandom' | ||
|
||
class OutputFile | ||
attr_reader :id | ||
|
||
attr_reader :output | ||
def initialize | ||
@id = SecureRandom.hex(10) | ||
create_file | ||
@output = Tempfile.new | ||
end | ||
|
||
def path | ||
"tmp/output-#{id}.log" | ||
@output.path | ||
end | ||
alias :to_s :path | ||
|
||
def read | ||
return unless File.exists?(path) | ||
|
||
File.read(path).split('[H[J').last | ||
@output.rewind | ||
@output.read.split('[H[J').last | ||
end | ||
|
||
def delete | ||
return unless File.exists?(path) | ||
|
||
File.delete(path) | ||
@output.close | ||
@output.unlink | ||
end | ||
alias :clear :delete | ||
|
||
private | ||
|
||
def create_file | ||
Dir.mkdir('tmp') unless Dir.exist?('tmp') | ||
File.open(path, "w") | ||
end | ||
end |
Oops, something went wrong.