This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
forked from sambroad/jasmine-gem
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
97 lines (84 loc) · 2.09 KB
/
spec_helper.rb
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
require 'rubygems'
require 'bundler'
require 'stringio'
require 'tmpdir'
envs = [:default, :development]
envs << :debug if ENV['DEBUG']
Bundler.setup(*envs)
$:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '../lib')))
require 'jasmine'
require 'rspec'
def create_rails(name)
`rails new #{name}`
end
def create_temp_dir
tmp = File.join(Dir.tmpdir, "jasmine-gem-test_#{Time.now.to_f}")
FileUtils.rm_r(tmp, :force => true)
FileUtils.mkdir(tmp)
tmp
end
def temp_dir_before
@root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
@old_dir = Dir::pwd
@tmp = create_temp_dir
end
def temp_dir_after
Dir::chdir @old_dir
FileUtils.rm_r @tmp
end
def custom_jasmine_config(prefix, &block)
require 'yaml'
support_path = File.join('spec', 'javascripts', 'support')
jasmine_config = YAML.load_file(File.join(support_path, 'jasmine.yml'))
block.call(jasmine_config)
custom_path = File.join(support_path, "#{prefix}_jasmine.yml")
File.open(custom_path, 'w') do |f|
f.write YAML.dump(jasmine_config)
f.flush
end
custom_path
end
module Kernel
def capture_stdout
out = StringIO.new
$stdout = out
yield
return out.string
ensure
$stdout = STDOUT
end
end
def passing_raw_result
{'id' => 123, 'status' => 'passed', 'fullName' => 'Passing test', 'description' => 'Passing', 'failedExpectations' => []}
end
def pending_raw_result
{'id' => 123, 'status' => 'pending', 'fullName' => 'Passing test', 'description' => 'Pending', 'failedExpectations' => []}
end
def failing_raw_result
{
'status' => 'failed',
'id' => 124,
'description' => 'a failing spec',
'fullName' => 'a suite with a failing spec',
'failedExpectations' => [
{
'message' => 'a failure message',
'stack' => 'a stack trace'
}
]
}
end
def failing_result_no_stack_trace
{
'status' => 'failed',
'id' => 124,
'description' => 'a failing spec',
'fullName' => 'a suite with a failing spec',
'failedExpectations' => [
{
'message' => 'a failure message, but no stack',
'stack' => nil
}
]
}
end