Class: Corundum::RSpec

Inherits:
DocumentationTask show all
Defined in:
lib/corundum/rspec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DocumentationTask

#entry_point, title

Instance Attribute Details

#report_taskObject (readonly)

Returns the value of attribute report_task.



29
30
31
# File 'lib/corundum/rspec.rb', line 29

def report_task
  @report_task
end

Instance Method Details

#default_configuration(toolkit) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/corundum/rspec.rb', line 31

def default_configuration(toolkit)
  super
  target_dir.relative_path = "rspec"
  self.qa_finished_path = toolkit.qa_file.abspath
  self.qa_rejections = toolkit.qa_rejections
  self.file_dependencies = file_lists.code + file_lists.test + file_lists.project
end

#defineObject



57
58
59
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/corundum/rspec.rb', line 57

def define
  super
  in_namespace do
    desc "Always run every spec"
    test_task(:all)

    desc "Generate specifications documentation"
    @report_task = doc_task(:doc => file_dependencies) do |t|
      t.rspec_opts += %w{-o /dev/null --failure-exit-code 0}
      t.formats["html"] = doc_path
      t.formats["json"] = json_report
    end
    file entry_point => :doc
    file json_report => :doc

    task :verify => json_report do |task|
      require 'json'
      require 'corundum/qa-report'

      doc = JSON::parse(File::read(json_report.to_s))

      rejections = QA::Report.new("RSpec[#{json_report}]")
      qa_rejections << rejections

      doc["examples"].find_all do |example|
        example["status"] == "failed"
      end.each do |failed|
        file,line,_ = failed["exception"]["backtrace"].first.split(":", 3)
        value = failed["exception"]["message"]
        rejections.add("fail", file, line, value)
      end

      unless rejections.empty?
        rejections.fail "Spec fails, none allowed"
      end
    end

    desc "Run only failing examples listed in last_run"
    test_task(:quick) do |t|
      examples = []
      begin
        File.open("last_run", "r") do |fail_list|
          fail_list.each_line.grep(%r{^\s*\d+\)\s*(.*)}) do |line|
            examples << $1.gsub(/'/){"[']"}
          end
        end
      rescue
      end
      unless examples.empty?
        t.rspec_opts << "--example"
        t.rspec_opts << "\"#{examples.join("|")}\""
      end
      t.failure_message = "Spec examples failed."
    end
  end

  desc "Run failing examples if any exist, otherwise, run the whole suite"
  task root_task => in_namespace(:quick)

  task :run_quality_assurance => in_namespace(:verify)
  task :run_continuous_integration => in_namespace(:verify)
end

#doc_task(name) ⇒ Object



51
52
53
54
55
# File 'lib/corundum/rspec.rb', line 51

def doc_task(name)
  RSpecReportTask.define_task(self, name) do |t|
    yield(t) if block_given?
  end
end

#resolve_configurationObject



39
40
41
42
43
# File 'lib/corundum/rspec.rb', line 39

def resolve_configuration
  self.rspec_path ||= %x"which #{rspec_program}".chomp
  resolve_paths
  super
end

#test_task(name) ⇒ Object



45
46
47
48
49
# File 'lib/corundum/rspec.rb', line 45

def test_task(name)
  RSpecTask.define_task(self, name) do |t|
    yield(t) if block_given?
  end
end