summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/spec_helper.rb
blob: 3a749581eee710a307958f18715b608fbb486605 (plain)
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
RSpec.configure do |config|
  config.disable_monkey_patching!
  config.raise_errors_for_deprecations!
end

require 'mspec'

# Remove this when MRI has intelligent warnings
$VERBOSE = nil unless $VERBOSE

class MOSConfig < Hash
  def initialize
    self[:loadpath]  = []
    self[:requires]  = []
    self[:flags]     = []
    self[:options]   = []
    self[:includes]  = []
    self[:excludes]  = []
    self[:patterns]  = []
    self[:xpatterns] = []
    self[:tags]      = []
    self[:xtags]     = []
    self[:atags]     = []
    self[:astrings]  = []
    self[:target]    = 'ruby'
    self[:command]   = nil
    self[:ltags]     = []
    self[:files]     = []
    self[:launch]    = []
  end
end

def new_option
  config = MOSConfig.new
  return MSpecOptions.new("spec", 20, config), config
end

# Just to have an exception name output not be "Exception"
class MSpecExampleError < Exception
end

def hide_deprecation_warnings
  allow(MSpec).to receive(:deprecate)
end

def run_mspec(command, args)
  cwd = Dir.pwd
  command = " #{command}" unless command.start_with?('-')
  cmd = "#{cwd}/bin/mspec#{command} -B spec/fixtures/config.mspec #{args}"
  out = `#{cmd} 2>&1`
  ret = $?
  out = out.sub(/\A\$.+\n/, '') # Remove printed command line
  out = out.sub(RUBY_DESCRIPTION, "RUBY_DESCRIPTION")
  out = out.gsub(/\d+\.\d{6}/, "D.DDDDDD") # Specs total time
  out = out.gsub(/\d{2}:\d{2}:\d{2}/, "00:00:00") # Progress bar time
  out = out.gsub(cwd, "CWD")
  return out, ret
end

def ensure_mspec_method(method)
  file, _line = method.source_location
  expect(file).to start_with(File.expand_path('../../lib/mspec', __FILE__ ))
end

PublicMSpecMatchers = Class.new {
  include MSpecMatchers
  public :raise_error
}.new