Module: Protest

Defined in:
lib/protest.rb,
lib/protest/rails.rb,
lib/protest/tests.rb,
lib/protest/utils.rb,
lib/protest/report.rb,
lib/protest/runner.rb,
lib/protest/test_case.rb,
lib/protest/utils/summaries.rb,
lib/protest/reports/progress.rb,
lib/protest/reports/documentation.rb,
lib/protest/utils/colorful_output.rb,
lib/protest/utils/backtrace_filter.rb

Defined Under Namespace

Modules: Rails, Reports, TestWithErrors, Utils Classes: AssertionFailed, ErroredTest, FailedTest, PassedTest, Pending, PendingTest, Report, Runner, Test, TestCase

Constant Summary collapse

VERSION =
"0.3.2"

Class Method Summary collapse

Class Method Details

.add_report(name, report) ⇒ Object

Register a new Report. This will make your report available to Protest, allowing you to run your tests through this report. For example

module Protest
  class Reports::MyAwesomeReport < Report
  end

  add_report :awesomesauce, MyAwesomeReport
end

See Protest.report_with to see how to select which report will be used.



21
22
23
# File 'lib/protest.rb', line 21

def self.add_report(name, report)
  available_reports[name] = report
end

.add_test_case(test_case) ⇒ Object

Register a test case to be run with Protest. This is done automatically whenever you subclass Protest::TestCase, so you probably shouldn’t pay much attention to this method.



28
29
30
# File 'lib/protest.rb', line 28

def self.add_test_case(test_case)
  available_test_cases << test_case
end

.autorun=(flag) ⇒ Object

Set to false to avoid running tests at_exit. Default is true.



33
34
35
# File 'lib/protest.rb', line 33

def self.autorun=(flag)
  @autorun = flag
end

.autorun?Boolean

Checks to see if tests should be run at_exit or not. Default is true. See Protest.autorun=

Returns:

  • (Boolean)


39
40
41
# File 'lib/protest.rb', line 39

def self.autorun?
  !!@autorun
end

.backtrace_filterObject

The object that filters the backtrace



75
76
77
# File 'lib/protest.rb', line 75

def self.backtrace_filter
  @backtrace_filter
end

.backtrace_filter=(filter) ⇒ Object

Set what object will filter the backtrace. It must respond to filter_backtrace, taking a backtrace array and a prefix path.



70
71
72
# File 'lib/protest.rb', line 70

def self.backtrace_filter=(filter)
  @backtrace_filter = filter
end

.context(description, &block) ⇒ Object Also known as: describe, story

Define a top level test context where to define tests. This works exactly the same as subclassing TestCase explicitly.

Protest.context "A user" do
  ...
end

is just syntax sugar to write:

class TestUser < Protest::TestCase
  self.description = "A user"
  ...
end


64
65
66
# File 'lib/protest/rails.rb', line 64

def self.context(description, &block)
  Rails::TestCase.context(description, &block)
end

.report(name, *report_args) ⇒ Object

Load a report by name, initializing it with the extra arguments provided. If the given name doesn’t match a report registered via Protest.add_report then the method will raise IndexError.



64
65
66
# File 'lib/protest.rb', line 64

def self.report(name, *report_args)
  available_reports.fetch(name).new(*report_args)
end

.report_with(name, *report_args) ⇒ Object

Select the name of the Report to use when running tests. See Protest.add_report for more information on registering a report.

Any extra arguments will be forwarded to the report’s #initialize method.

The default report is Protest::Reports::Progress



57
58
59
# File 'lib/protest.rb', line 57

def self.report_with(name, *report_args)
  @report = report(name, *report_args)
end

.root_test_casesObject



79
80
81
82
83
# File 'lib/protest.rb', line 79

def self.root_test_cases
  v = available_test_cases.select {|tc| tc.superclass == Protest::TestCase }
  #pp :root_test_cases => v
  v
end

.run_all_tests!(*report_args) ⇒ Object

Run all registered test cases through the selected report. You can pass arguments to the Report constructor here.

See Protest.add_test_case and Protest.report_with



47
48
49
# File 'lib/protest.rb', line 47

def self.run_all_tests!(*report_args)
  Runner.new(@report).run(*root_test_cases)
end