Class: PLSQL::Spec::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/plsql/spec/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



15
16
17
18
# File 'lib/plsql/spec/cli.rb', line 15

def initialize(*)
  super
  self.source_paths << File.expand_path('../templates', __FILE__)
end

Instance Method Details

#diff(file1, file2) ⇒ Object



103
104
105
106
# File 'lib/plsql/spec/cli.rb', line 103

def diff(file1, file2)
  differ = RSpec::Support::Differ.new
  say differ.diff_as_string File.read(file2), File.read(file1)
end

#initObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/plsql/spec/cli.rb', line 23

def init
  empty_directory 'spec/factories'
  copy_file '.rspec', '.rspec'
  directory 'spec', 'spec'
  say <<-EOS, :red

Please update spec/database.yml file and specify your database connection parameters.

Create tests in spec/ directory (or in subdirectories of it) in *_spec.rb files.

Run created tests with "plsql-spec run".
Run tests with "plsql-spec run --coverage" to generate code coverage report in coverage/ directory.
Run tests with "plsql-spec run --html" to generate RSpec report to test-results.html file.
EOS
end

#run_tests(*files) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/plsql/spec/cli.rb', line 60

def run_tests(*files)
  unless File.directory?('spec')
    say "No spec subdirectory in current directory", :red
    exit 1
  end
  ENV['PLSQL_DBMS_OUTPUT'] = 'true' if options[:"dbms-output"]
  ENV['PLSQL_HTML'] = options[:html] if options[:html]
  ENV['PLSQL_COVERAGE'] = options[:coverage] if options[:coverage]
  ENV['PLSQL_COVERAGE_IGNORE_SCHEMAS'] = options[:"ignore-schemas"].join(',') if options[:"ignore-schemas"]
  ENV['PLSQL_COVERAGE_LIKE'] = options[:like].join(',') if options[:like]

  if options[:html]
    # if there is no filename given, the options[:html] == "html"
    spec_output_filename = options[:html] == 'html' ? 'test-results.html' : options[:html]

    speccommand = "rspec --format html --out #{spec_output_filename}"
  else
    speccommand = "rspec"
  end

  if files.empty?
    say "Running all specs from spec/", :yellow
    puts run("#{speccommand} spec", :verbose => false, :capture => options[:capture])
  else
    say "Running specs from #{files.join(', ')}", :yellow
    puts run("#{speccommand} #{files.join(' ')}", :verbose => false, :capture => options[:capture])
  end

  if options[:html]
    say "Test results in #{spec_output_filename}"
  end

  if options[:coverage]
    say "Coverage report in #{options[:coverage]}/index.html"
  end

  unless $?.exitstatus == 0
    say "Failing tests!", :red
    exit 1
  end
end

#versionObject



109
110
111
112
113
# File 'lib/plsql/spec/cli.rb', line 109

def version
  say "ruby-plsql-spec #{PLSQL::Spec::VERSION}"
  say "ruby-plsql      #{PLSQL::VERSION}"
  say "rspec           #{::RSpec::Version::STRING}"
end