Class: Ree::SpecRunner::CommandGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/ree/spec_runner/command_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package_name:, package_path:, spec_matcher:, spec_string_number:, show_output: true) ⇒ CommandGenerator

Returns a new instance of CommandGenerator.



6
7
8
9
10
11
12
# File 'lib/ree/spec_runner/command_generator.rb', line 6

def initialize(package_name:, package_path:, spec_matcher:, spec_string_number:, show_output: true)
  @package_name = package_name
  @package_path = File.expand_path(package_path)
  @spec_matcher = spec_matcher
  @spec_string_number = spec_string_number
  @output = show_output ? '$stdout' : 'File::NULL'
end

Instance Attribute Details

#package_nameObject

Returns the value of attribute package_name.



4
5
6
# File 'lib/ree/spec_runner/command_generator.rb', line 4

def package_name
  @package_name
end

#package_pathObject

Returns the value of attribute package_path.



4
5
6
# File 'lib/ree/spec_runner/command_generator.rb', line 4

def package_path
  @package_path
end

#spec_matcherObject

Returns the value of attribute spec_matcher.



4
5
6
# File 'lib/ree/spec_runner/command_generator.rb', line 4

def spec_matcher
  @spec_matcher
end

#spec_string_numberObject

Returns the value of attribute spec_string_number.



4
5
6
# File 'lib/ree/spec_runner/command_generator.rb', line 4

def spec_string_number
  @spec_string_number
end

Instance Method Details

#commandObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ree/spec_runner/command_generator.rb', line 18

def command
  package_spec_path = File.join(package_path, 'spec')
  package_spec_helper = File.join(package_path, 'spec', 'spec_helper.rb')
  matcher = ""

  if spec_matcher
    matched_file = File.expand_path(spec_matcher, package_path)
    matcher = File.exist?(matched_file) ? matcher_with_number(matched_file, spec_string_number) : matcher_with_number(spec_matcher, spec_string_number)
  end

  "print_message(
      '**** Package: #{package_name}  *****') \\
        && system('cd #{Ree.root_dir} \\
        && bundle exec rspec --color --tty #{matcher} --default-path=#{package_spec_path} --require=#{package_spec_helper}', \\
        out: #{@output.to_s}, err: :out)"
end

#generateObject



35
36
37
38
39
40
41
42
# File 'lib/ree/spec_runner/command_generator.rb', line 35

def generate
  Ree::SpecRunner::CommandParams.new.tap do |cp|
    cp.package_name = package_name
    cp.package_path = package_path
    cp.command      = command
    cp.spec_count   = spec_count
  end
end

#spec_countObject



14
15
16
# File 'lib/ree/spec_runner/command_generator.rb', line 14

def spec_count
  Dir[File.join(package_path, 'spec/**/*_spec.rb')].size
end