File: Rakefile

package info (click to toggle)
ruby-mocha 1.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,440 kB
  • sloc: ruby: 11,613; makefile: 13
file content (156 lines) | stat: -rw-r--r-- 4,988 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
require 'bundler'
Bundler::GemHelper.install_tasks
require 'bundler/setup'

MOCHA_DOCS_HOST = ENV['MOCHA_DOCS_HOST'] || 'gofreerange.com'

require 'rake/testtask'

desc 'Run all tests'
task 'default' => ['test', 'test:performance']

desc 'Run tests'
task 'test' do
  if (test_library = ENV['MOCHA_RUN_INTEGRATION_TESTS'])
    Rake::Task["test:integration:#{test_library}"].invoke
  else
    Rake::Task['test:units'].invoke
    Rake::Task['test:acceptance'].invoke
  end
end

namespace 'test' do
  unit_tests = FileList['test/unit/**/*_test.rb']
  all_acceptance_tests = FileList['test/acceptance/*_test.rb']
  ruby186_incompatible_acceptance_tests = FileList['test/acceptance/stub_class_method_defined_on_*_test.rb'] + FileList['test/acceptance/stub_instance_method_defined_on_*_test.rb']
  ruby186_compatible_acceptance_tests = all_acceptance_tests - ruby186_incompatible_acceptance_tests

  desc 'Run unit tests'
  Rake::TestTask.new('units') do |t|
    t.libs << 'test'
    t.test_files = unit_tests
    t.verbose = true
    t.warning = true
  end

  desc 'Run acceptance tests'
  Rake::TestTask.new('acceptance') do |t|
    t.libs << 'test'
    t.test_files = if defined?(RUBY_VERSION) && (RUBY_VERSION >= '1.8.7')
                     all_acceptance_tests
                   else
                     ruby186_compatible_acceptance_tests
                   end
    t.verbose = true
    t.warning = true
  end

  namespace 'integration' do
    desc 'Run MiniTest integration tests (intended to be run in its own process)'
    Rake::TestTask.new('minitest') do |t|
      t.libs << 'test'
      t.test_files = FileList['test/integration/mini_test_test.rb']
      t.verbose = true
      t.warning = true
    end

    desc 'Run Test::Unit integration tests (intended to be run in its own process)'
    Rake::TestTask.new('test-unit') do |t|
      t.libs << 'test'
      t.test_files = FileList['test/integration/test_unit_test.rb']
      t.verbose = true
      t.warning = true
    end
  end

  # require 'rcov/rcovtask'
  # Rcov::RcovTask.new('coverage') do |t|
  #   t.libs << 'test'
  #   t.test_files = unit_tests + acceptance_tests
  #   t.verbose = true
  #   t.warning = true
  #   t.rcov_opts << '--sort coverage'
  #   t.rcov_opts << '--xref'
  # end

  desc 'Run performance tests'
  task 'performance' do
    require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'stubba_example_test')
    require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'mocha_example_test')
    iterations = 1000
    puts "\nBenchmarking with #{iterations} iterations..."
    [MochaExampleTest, StubbaExampleTest].each do |test_case|
      puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds."
    end
  end
end

begin
  require 'rubocop/rake_task'
  if RUBY_VERSION >= '2.2.0'
    RuboCop::RakeTask.new
    task 'test' => 'rubocop'
  end
rescue LoadError # rubocop:disable Lint/HandleExceptions
end

def benchmark_test_case(klass, iterations)
  require 'benchmark'
  require 'mocha/detection/mini_test'

  if defined?(MiniTest)
    minitest_version = Gem::Version.new(Mocha::Detection::MiniTest.version)
    if Gem::Requirement.new('>= 5.0.0').satisfied_by?(minitest_version)
      result = Benchmark.realtime { iterations.times { |_i| klass.run(MiniTest::CompositeReporter.new) } }
      MiniTest::Runnable.runnables.delete(klass)
      result
    else
      MiniTest::Unit.output = StringIO.new
      Benchmark.realtime { iterations.times { |_i| MiniTest::Unit.new.run([klass]) } }
    end
  else
    load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
    unless @silent_option
      begin
        load 'test/unit/ui/console/outputlevel.rb' unless defined?(Test::Unit::UI::Console::OutputLevel::SILENT)
        @silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
      rescue LoadError
        @silent_option = Test::Unit::UI::SILENT
      end
    end
    Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, @silent_option) } }
  end
end

if ENV['MOCHA_GENERATE_DOCS']
  require 'yard'

  desc 'Remove generated documentation'
  task 'clobber_yardoc' do
    `rm -rf ./doc`
  end

  task 'docs_environment' do
    unless ENV['GOOGLE_ANALYTICS_WEB_PROPERTY_ID']
      puts "\nWarning: GOOGLE_ANALYTICS_WEB_PROPERTY_ID was not defined\n\n"
    end
  end

  desc 'Generate documentation'
  YARD::Rake::YardocTask.new('yardoc' => 'docs_environment') do |task|
    task.options = ['--title', "Mocha #{Mocha::VERSION}"]
  end

  desc 'Generate documentation'
  task 'generate_docs' => %w[clobber_yardoc yardoc]

  desc "Publish docs to #{MOCHA_DOCS_HOST}/docs/mocha"
  task 'publish_docs' => 'generate_docs' do
    path = '/home/freerange/docs/mocha'
    system %(ssh #{MOCHA_DOCS_HOST} "sudo rm -fr #{path} && mkdir -p #{path}" && scp -r doc/* #{MOCHA_DOCS_HOST}:#{path})
  end
end

task 'release' => 'default' do
  Rake::Task['publish_docs'].invoke
end