Skip to content

Commit

Permalink
Create Command::Hardcoded
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexB52 committed Nov 23, 2024
1 parent 1cac2d2 commit b0d7906
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 32 deletions.
2 changes: 2 additions & 0 deletions lib/retest/command.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require_relative 'command/base'
require_relative 'command/hardcoded'
require_relative 'command/rails'
require_relative 'command/rake'
require_relative 'command/rspec'
Expand Down
23 changes: 23 additions & 0 deletions lib/retest/command/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Retest
class Command
class Base
def initialize(all: false, file_system: FileSystem, command: nil)
@file_system = file_system
@all = all
@command = command
end

def to_s
raise NotImplementedError
end

def format_batch(*files)
raise NotImplementedError
end

private

attr_reader :all, :file_system, :command
end
end
end
12 changes: 12 additions & 0 deletions lib/retest/command/hardcoded.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Retest
class Command
class Hardcoded < Base
def to_s
@command
end

def format_batch(*files)
end
end
end
end
9 changes: 1 addition & 8 deletions lib/retest/command/rails.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module Retest
class Command
class Rails
attr_reader :all, :file_system

def initialize(all:, file_system: FileSystem)
@file_system = file_system
@all = all
end

class Rails < Base
def to_s
return "#{root_command} <test>" unless all
root_command
Expand Down
9 changes: 1 addition & 8 deletions lib/retest/command/rake.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module Retest
class Command
class Rake
attr_reader :all, :file_system

def initialize(all:, file_system: FileSystem)
@file_system = file_system
@all = all
end

class Rake < Base
def to_s
return "#{root_command} TEST=<test>" unless all
root_command
Expand Down
9 changes: 1 addition & 8 deletions lib/retest/command/rspec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module Retest
class Command
class Rspec
attr_reader :all, :file_system

def initialize(all:, file_system: FileSystem)
@file_system = file_system
@all = all
end

class Rspec < Base
def to_s
return "#{root_command} <test>" unless all
root_command
Expand Down
9 changes: 1 addition & 8 deletions lib/retest/command/ruby.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
module Retest
class Command
class Ruby
attr_reader :all, :file_system

def initialize(all:, file_system: FileSystem)
@file_system = file_system
@all = all
end

class Ruby < Base
def format_batch(*files)
%Q{-e "#{files.map { |file| "require './#{file}';" }.join}"}
end
Expand Down
5 changes: 5 additions & 0 deletions test/retest/command/command_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ def test_interface
assert_respond_to @subject, :format_batch
assert_respond_to @subject, :to_s
end

def test_initializatioin
@subject.class.new
@subject.class.new(all: '', file_system: '', command: '')
end
end
end
end
26 changes: 26 additions & 0 deletions test/retest/command/hardcoded_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'test_helper'
require_relative 'command_interface'

module Retest
class Command
class HardcodedTest < MiniTest::Test
def setup
@subject = Hardcoded.new(command: 'echo "hello world"')
end

include CommandInterface

def test_to_s
assert_equal 'echo "hello world"', @subject.to_s
end

def test_format_with_one_file
assert_nil @subject.format_batch('a/file/path.rb')
end

def test_format_with_multiple_files
assert_nil @subject.format_batch('a/file/path.rb', 'another/file/path.rb')
end
end
end
end

0 comments on commit b0d7906

Please sign in to comment.