Module: Roby::App::Rake

Defined in:
lib/roby/app/rake.rb

Overview

Utility for Rakefile’s in the generated apps

Tests

TestTask generates a set of Rake tasks which run the tests. One task is created per robot configuration in ‘config/robots/`, and one “test” task is created that runs all the others. For instance, adding

Roby::App::Rake::TestTask.new

in an app that has ‘config/robots/default.rb` and `config/robots/live.rb` will generate the `test:default`, `test:live` and `test` tasks.

See TestTask documentation for possible configuration. Attributes can be modified in a block passed to ‘new`, e.g.:

Roby::App::Rake::TestTask.new do |t|
    t.robot_names.delete(%w[default default])
end

The tests will by default run the default minitest reporter. However, if the JUNIT environment variable is set to 1, they will instead be configured to generate a junit-compatible report. The report is named after the robot configuration (e.g. ‘default:default.junit.xml`) and placed in the report dir.

The report dir is by default a ‘.test-results` folder at the root of the app. It can be changed by setting the `REPORT_DIR` environment variable.

Rubocop

Rake.define_rubocop will configure a “rubocop” task. Its sibling, Rake.define_rubocop_if_enabled will do so, but controlled by a ‘RUBOCOP` environment variable:

- `RUBOCOP=1` will require that rubocop is present and define the
  task
- `RUBOCOP=0` will never define the task
- any other value (including not having the variable defined) will
  define the task only if rubocop is available.

Note that the method only defines the task. If you mean to have it run along with the tests, you must add it explicitely as a dependency

task "test" => "rubocop"

When using Rake.define_rubocop_if_enabled, use the method’s return value to guard against the cases where the task is not defined, e.g.

task "test" => "rubocop" if Roby::App::Rake.define_rubocop_if_enabled

The task uses rubocop’s standard output formatter by default. However, if the JUNIT environment variable is set to 1, it will instead be configured to generate a junit-compatible report named ‘rubocop.junit.xml` in the same report dir than the tests.

The report dir is by default a ‘.test-results` folder at the root of the app. It can be changed by setting the `REPORT_DIR` environment variable.

Defined Under Namespace

Classes: BaseTestTask, RobotTestTask, TestTask

Class Method Summary collapse

Class Method Details

.coverage?Boolean

Whether code coverage reports should be generated

Returns:

  • (Boolean)


119
120
121
# File 'lib/roby/app/rake.rb', line 119

def self.coverage?
    ENV["ROBY_TEST_COVERAGE"] == "1"
end

.define_rubocop(junit: Rake.use_junit?, report_dir: Rake.report_dir) ⇒ Object



653
654
655
656
657
658
659
660
661
662
663
# File 'lib/roby/app/rake.rb', line 653

def self.define_rubocop(
    junit: Rake.use_junit?, report_dir: Rake.report_dir
)
    require "rubocop/rake_task"
    RuboCop::RakeTask.new do |t|
        if junit
            t.formatters << "junit"
            t.options << "-o" << "#{report_dir}/rubocop.junit.xml"
        end
    end
end

.define_rubocop_if_enabled(junit: Rake.use_junit?, report_dir: Rake.report_dir, required: Rake.require_rubocop?) ⇒ Object



635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/roby/app/rake.rb', line 635

def self.define_rubocop_if_enabled(
    junit: Rake.use_junit?, report_dir: Rake.report_dir,
    required: Rake.require_rubocop?
)
    return false unless Rake.use_rubocop?

    begin
        require "rubocop/rake_task"
    rescue LoadError
        raise if required

        return
    end

    define_rubocop(junit: junit, report_dir: report_dir)
    true
end

.keep_logs?Boolean

Whether the tests and rubocop should generate a JUnit report

This is false by default, true if the JUNIT environment variable is set to 1

Returns:

  • (Boolean)


98
99
100
# File 'lib/roby/app/rake.rb', line 98

def self.keep_logs?
    ENV["ROBY_TEST_KEEP_LOGS"] == "1"
end

.report_dirObject

The reporting dir when generating JUnit reports

Defaults to the current dir ‘.test-results` subdirectory. Can be overriden with the REPORT_DIR environment variable



114
115
116
# File 'lib/roby/app/rake.rb', line 114

def self.report_dir
    ENV["REPORT_DIR"] || File.expand_path(".test-results")
end

.report_sync_mutexObject



123
124
125
# File 'lib/roby/app/rake.rb', line 123

def self.report_sync_mutex
    @report_sync_mutex ||= Mutex.new
end

.require_rubocop?Boolean

Whether the define_rubocop_if_enabled should fail if rubocop is not available

It is true if RUBOCOP is set to 1. If RUBOCOP is set to anything else that is not 0, define_rubocop_if_enabled will enable rubocop only if it is available

Returns:

  • (Boolean)


79
80
81
# File 'lib/roby/app/rake.rb', line 79

def self.require_rubocop?
    ENV["RUBOCOP"] == "1"
end

.use_junit?Boolean

Whether the tests and rubocop should generate a JUnit report

This is false by default, true if the JUNIT environment variable is set to 1

Returns:

  • (Boolean)


106
107
108
# File 'lib/roby/app/rake.rb', line 106

def self.use_junit?
    ENV["JUNIT"] == "1"
end

.use_rubocop?Boolean

Whether the tests should run RuboCop, as defined by the RUBOCOP environment variable

It is true by default, false if the RUBOCOP environment variable is set to 0

This affects define_rubocop_if_enabled

Returns:

  • (Boolean)


90
91
92
# File 'lib/roby/app/rake.rb', line 90

def self.use_rubocop?
    ENV["RUBOCOP"] != "0"
end