-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Koine | ||
class TestRunner | ||
class Adapters | ||
class CustomAdapter < BaseRegexpAdapter | ||
def initialize(file_pattern:, command: nil, commands: {}) | ||
super(file_pattern: file_pattern) | ||
@command = command | ||
@commands = {}.tap do |hash| | ||
commands.each do |key, value| | ||
hash[key.to_sym] = value | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def all_tests(config) | ||
command(command_for(:all), config) | ||
end | ||
|
||
def single_file_command(config) | ||
command(command_for(:file), config) | ||
end | ||
|
||
def file_line_command(config) | ||
command(command_for(:line), config) | ||
end | ||
|
||
def command_for(type) | ||
@commands.fetch(type).to_s | ||
end | ||
|
||
def command(template, config) | ||
template.sub('{command}', @command) | ||
.sub('{file}', config.file_path.to_s) | ||
.sub('{line}', config.line.to_s) | ||
end | ||
end | ||
end | ||
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
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,53 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Koine::TestRunner::Adapters::CustomAdapter do | ||
let(:file) { 'foo/bar/baz/file_spec.rb' } | ||
|
||
let(:adapter) do | ||
described_class.new( | ||
file_pattern: /_spec.rb$/, | ||
command: './bin/rspec', | ||
commands: { | ||
all: '{command}', | ||
'file' => '{command} {file}', | ||
'line' => '{command} {file}:{line}' | ||
} | ||
) | ||
end | ||
|
||
subject { MockAdapter.succeed(adapter) } | ||
|
||
it 'is a file pattern based adapter' do | ||
expect(subject).to be_a(Koine::TestRunner::Adapters::BaseRegexpAdapter) | ||
end | ||
|
||
it 'inores files that is none of it\'s concern' do | ||
config = Factory.config('some-other-file') | ||
|
||
expect(subject.test_command(config)).to be_nil | ||
end | ||
|
||
it 'returns the command for all files' do | ||
config = Factory.config(file, '--all') | ||
|
||
command = subject.test_command(config) | ||
|
||
expect(command).to eq('./bin/rspec') | ||
end | ||
|
||
it 'returns the command for single file' do | ||
config = Factory.config(file) | ||
|
||
command = subject.test_command(config) | ||
|
||
expect(command).to eq("./bin/rspec #{file}") | ||
end | ||
|
||
it 'returns the command for single file filtered by line' do | ||
config = Factory.config(file, '--line=10') | ||
|
||
command = subject.test_command(config) | ||
|
||
expect(command).to eq("./bin/rspec #{file}:10") | ||
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
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