data_maker 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +139 -0
- data/data_maker.gemspec +64 -0
- data/lib/data_maker/china/phone_number.rb +101 -0
- data/lib/data_maker/data/china/phone_number/landline_phone_prefixes +328 -0
- data/lib/data_maker/data/china/phone_number/mobile_phone_prefixes +40 -0
- data/lib/data_maker/utilities/array_utilities.rb +36 -0
- data/lib/data_maker/utilities/module_utilities.rb +30 -0
- data/lib/data_maker/validators/chinese_phone_number.rb +28 -0
- data/lib/data_maker.rb +63 -0
- data/spec/lib/data_maker/china/phone_number_spec.rb +82 -0
- data/spec/lib/data_maker/data_maker_spec.rb +138 -0
- data/spec/lib/data_maker/support/matchers/phone_number_matcher.rb +42 -0
- data/spec/lib/data_maker/utilities/array_utilities_spec.rb +101 -0
- data/spec/lib/data_maker/utilities/module_utilities_spec.rb +0 -0
- data/spec/spec_helper.rb +41 -0
- metadata +230 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
130
|
2
|
+
131
|
3
|
+
132
|
4
|
+
133
|
5
|
+
1340
|
6
|
+
1348
|
7
|
+
1349
|
8
|
+
135
|
9
|
+
135
|
10
|
+
136
|
11
|
+
137
|
12
|
+
138
|
13
|
+
139
|
14
|
+
145
|
15
|
+
147
|
16
|
+
150
|
17
|
+
151
|
18
|
+
152
|
19
|
+
158
|
20
|
+
159
|
21
|
+
153
|
22
|
+
155
|
23
|
+
156
|
24
|
+
157
|
25
|
+
1700
|
26
|
+
1705
|
27
|
+
1709
|
28
|
+
176
|
29
|
+
177
|
30
|
+
178
|
31
|
+
180
|
32
|
+
181
|
33
|
+
182
|
34
|
+
183
|
35
|
+
184
|
36
|
+
187
|
37
|
+
185
|
38
|
+
186
|
39
|
+
188
|
40
|
+
189
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module DataMaker
|
2
|
+
module ArrayUtilities
|
3
|
+
def self.const_array(argument)
|
4
|
+
array = argument.is_a?(Array) ? argument : argument.to_a
|
5
|
+
array.extend ArrayUtilities
|
6
|
+
freeze_all(array)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.random_pick(array, n)
|
10
|
+
indexes = (0...array.length).sort_by{Kernel.rand}[0...n]
|
11
|
+
indexes.map { |n| array[n].dup }
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.freeze_all(array)
|
15
|
+
array.each(&:freeze)
|
16
|
+
array.freeze
|
17
|
+
array
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.shuffle(array)
|
21
|
+
array.sort_by{Kernel.rand}
|
22
|
+
end
|
23
|
+
|
24
|
+
def random_pick(n)
|
25
|
+
ArrayUtilities.random_pick(self, n)
|
26
|
+
end
|
27
|
+
|
28
|
+
def freeze_all
|
29
|
+
ArrayUtilities.freeze_all(self)
|
30
|
+
end
|
31
|
+
|
32
|
+
def shuffle
|
33
|
+
ArrayUtilities.shuffle(self)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'data_maker/utilities/array_utilities'
|
2
|
+
|
3
|
+
module DataMaker
|
4
|
+
module ModuleUtilities
|
5
|
+
def k(arg)
|
6
|
+
DataMaker::ArrayUtilities.const_array(arg)
|
7
|
+
end
|
8
|
+
|
9
|
+
def const_missing(const_name)
|
10
|
+
if const_name =~ /[a-z]/ # Not a constant, probably a class/module name.
|
11
|
+
super const_name
|
12
|
+
else
|
13
|
+
locale = ancestors.first.to_s.split("::")[-2]
|
14
|
+
mod_name = ancestors.first.to_s.split("::").last
|
15
|
+
data_path = "#{DataMaker::BASE_LIB_PATH}/data_maker/data/#{underscore(locale)}/#{underscore(mod_name)}/#{underscore(const_name.to_s)}"
|
16
|
+
data = k File.read(data_path).split("\n")
|
17
|
+
const_set const_name, data
|
18
|
+
data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def underscore(string)
|
23
|
+
string.gsub(/::/, '/').
|
24
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
25
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
26
|
+
tr("-", "_").
|
27
|
+
downcase
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module DataMaker
|
2
|
+
module Validators
|
3
|
+
class ChinesePhoneNumber
|
4
|
+
def initialize(number)
|
5
|
+
@number = number
|
6
|
+
end
|
7
|
+
|
8
|
+
def mobile?
|
9
|
+
mobile_regex = /^1[34578]\d(\D?)\d{4}(\D?)\d{4}$/
|
10
|
+
!(mobile_regex.match(@number.to_s).nil?)
|
11
|
+
end
|
12
|
+
|
13
|
+
def landline?
|
14
|
+
twodigit = /^0?((10)|(2[0-57-9])|(3[157])|(4[17])|(5[1,3,5])|(7[1579])|(8[357])|(9[379]))\d{8,9}$/
|
15
|
+
threedigit = /^0?(((335|349|39[1-6]|398))|((42[179]|43[1-9]|44[08]|45[1-9]|46[4789]|48[23]))|((52[37]|54[36]|56[1-6]|580|59[1-9]))|((63[1-5]|66[0238]|69[12]))|((701|72[248]|73[014-9]|74[3-6]|76[023689]))|((81[23678]|82[5-7]|88[136-8]|89[1-8]))|((90[123689]|91[1-9]|94[13]|95[1-5])))\d{7,}$/
|
16
|
+
fourdigit = /^0?((8029|806[03578]|807[01])\d{6,})$/
|
17
|
+
|
18
|
+
!(twodigit.match(@number.to_s).nil?) ||
|
19
|
+
!(threedigit.match(@number.to_s).nil?) ||
|
20
|
+
!(fourdigit.match(@number.to_s).nil?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?
|
24
|
+
mobile? || landline?
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/data_maker.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module DataMaker
|
2
|
+
VERSION = "2.0.0"
|
3
|
+
|
4
|
+
require 'data_maker/utilities/array_utilities'
|
5
|
+
require 'data_maker/utilities/module_utilities'
|
6
|
+
|
7
|
+
extend ModuleUtilities
|
8
|
+
|
9
|
+
BASE_LIB_PATH = File.expand_path("..", __FILE__)
|
10
|
+
|
11
|
+
LETTERS = [*'a'..'z']
|
12
|
+
|
13
|
+
HEX = %w(0 1 2 3 4 5 6 7 8 9 A B C D E F)
|
14
|
+
|
15
|
+
def self.hexify(*masks)
|
16
|
+
begin
|
17
|
+
if valid_mask?(*masks, /#/)
|
18
|
+
masks.flatten.sample.gsub(/#/) { HEX.sample }
|
19
|
+
end
|
20
|
+
rescue
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.numerify(*masks)
|
26
|
+
begin
|
27
|
+
if valid_mask?(*masks, /#/)
|
28
|
+
masks.flatten.sample.gsub(/#/) { rand(10).to_s }
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
return false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.letterify(*masks)
|
36
|
+
begin
|
37
|
+
if valid_mask?(*masks, /\?/)
|
38
|
+
masks.flatten.sample.gsub(/\?/) { LETTERS.sample }
|
39
|
+
end
|
40
|
+
rescue
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.alphanumerify(masks)
|
46
|
+
letterify(numerify(masks))
|
47
|
+
end
|
48
|
+
|
49
|
+
# Load all constants.
|
50
|
+
Dir["#{BASE_LIB_PATH}/data_maker/**/*.rb"].sort.each do |f|
|
51
|
+
require f
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.valid_mask?(*masks, match_with)
|
55
|
+
masks.each do |mask|
|
56
|
+
unless mask.match(match_with)
|
57
|
+
raise ArgumentError, "You must pass a #{match_with} sign sir!"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private_class_method :valid_mask?
|
63
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe DataMaker::China::PhoneNumber do
|
4
|
+
let(:phone_number) { described_class }
|
5
|
+
|
6
|
+
describe "#self.mobile" do
|
7
|
+
it "generates a valid mobile number" do
|
8
|
+
number = phone_number.mobile
|
9
|
+
validate = DataMaker::Validators::ChinesePhoneNumber.new(number)
|
10
|
+
expect(validate.valid?).to be_truthy
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#self.landline" do
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "::GeneratePhoneNumber" do
|
18
|
+
let(:generate_phone_number) { described_class::PhoneNumberGenerator.new(format) }
|
19
|
+
let(:format) { ["mobile", "landline"].sample }
|
20
|
+
|
21
|
+
describe "#mobile_prefix" do
|
22
|
+
let(:mobile_prefix) { generate_phone_number.mobile_prefix }
|
23
|
+
|
24
|
+
# context "when MobilePhonePrefix.empty? is true" do
|
25
|
+
# before :each do
|
26
|
+
# end
|
27
|
+
|
28
|
+
# it "raises an error" do
|
29
|
+
# expect { mobile_prefix }.to raise_error
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
|
33
|
+
context "when MobilePhonePrefix.empty? is false" do
|
34
|
+
it "returns a sample" do
|
35
|
+
expect(mobile_prefix).to_not be_empty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#generate_number" do
|
41
|
+
let(:generate) { generate_phone_number.generate }
|
42
|
+
|
43
|
+
it "generates a valid phone number" do
|
44
|
+
number = generate
|
45
|
+
validate = DataMaker::Validators::ChinesePhoneNumber.new(number)
|
46
|
+
expect(validate.valid?).to be_truthy
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when format is mobile" do
|
50
|
+
let(:format) { "mobile" }
|
51
|
+
|
52
|
+
it "generates an 11 digit number" do
|
53
|
+
expect(generate.length).to eq(11)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "when format is landline" do
|
58
|
+
let(:format) { "landline" }
|
59
|
+
|
60
|
+
context "when eleven_digit_rule? is true" do
|
61
|
+
before :each do
|
62
|
+
allow(generate_phone_number).to receive(:eleven_digit_rule?).and_return(true)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "generates an 11 digit number" do
|
66
|
+
expect(generate.length).to eq(11)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when eleven_digit_rule? is false" do
|
71
|
+
before :each do
|
72
|
+
allow(generate_phone_number).to receive(:eleven_digit_rule?).and_return(false)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "generates an 10 digit number" do
|
76
|
+
expect(generate.length).to eq(10)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe DataMaker do
|
4
|
+
let(:masks) { value }
|
5
|
+
|
6
|
+
describe "#VERSION" do
|
7
|
+
# For each iteration of a version this would always get changed.
|
8
|
+
let(:current_version) { "2.0.0" }
|
9
|
+
|
10
|
+
it { expect(described_class).to be_const_defined(:VERSION) }
|
11
|
+
it { expect(described_class::VERSION).to eq(current_version) }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "#self.hexify" do
|
15
|
+
let(:regex) { /\b[a-zA-Z0-9]{3}\b/ }
|
16
|
+
|
17
|
+
context "when valid_masks? is true" do
|
18
|
+
let(:value) { "### hello ###" }
|
19
|
+
|
20
|
+
it "returns a hexed value" do
|
21
|
+
expect(described_class.hexify(*masks)).to match(regex)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when passed an array value" do
|
25
|
+
let(:value) { ["hello ###", "my ### is ###"] }
|
26
|
+
|
27
|
+
it "returns a hexed value" do
|
28
|
+
expect(described_class.hexify(*masks)).to match(regex)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "when valid_masks? raises an error" do
|
34
|
+
let(:value) { "hello my name is banana" }
|
35
|
+
|
36
|
+
it "returns false" do
|
37
|
+
expect(described_class.hexify(*masks)).to be_falsey
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#self.numerify" do
|
43
|
+
let(:regex) { /\b[0-9]{3}\b/ }
|
44
|
+
|
45
|
+
context "when valid_masks? is true" do
|
46
|
+
let(:value) { "my phone number is ###" }
|
47
|
+
|
48
|
+
it "returns a numeric value" do
|
49
|
+
expect(described_class.numerify(*masks)).to match(regex)
|
50
|
+
end
|
51
|
+
|
52
|
+
context "when passed an array value" do
|
53
|
+
let(:value) { ["my phone number is ###", "unit no. ###"] }
|
54
|
+
|
55
|
+
it "returns a numeric value" do
|
56
|
+
expect(described_class.numerify(*masks)).to match(regex)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when valid_masks? raises an error" do
|
62
|
+
let(:value) { ["my phone number is 3333", "unit no. seven"] }
|
63
|
+
|
64
|
+
it "returns false" do
|
65
|
+
expect(described_class.numerify(*masks)).to be_falsey
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#self.letterify" do
|
71
|
+
let(:regex) { /\b[a-z]{3}\b/ }
|
72
|
+
|
73
|
+
context "when valid_masks? is true" do
|
74
|
+
let(:value) { "convert me to letters ???" }
|
75
|
+
|
76
|
+
it "returns alphabetic characters" do
|
77
|
+
expect(described_class.letterify(*masks)).to match(regex)
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when passed an array value" do
|
81
|
+
let(:value) { ["convert me ???", "me too ???"] }
|
82
|
+
|
83
|
+
it "returns alphabetic characters" do
|
84
|
+
expect(described_class.letterify(*masks)).to match(regex)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when valid_masks? raises an error" do
|
90
|
+
let(:value) { "convert me to letters ###" }
|
91
|
+
|
92
|
+
it "returns false" do
|
93
|
+
expect(described_class.letterify(*masks)).to be_falsey
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#self.alphanumerify" do
|
99
|
+
let(:regex) { /\b[a-zA-Z0-9]{3}\b/ }
|
100
|
+
|
101
|
+
context "when valid_masks? is true" do
|
102
|
+
let(:value) { "alphanumerify me ##?" }
|
103
|
+
|
104
|
+
it "returns alphanumeric characters" do
|
105
|
+
expect(described_class.alphanumerify(*masks)).to match(regex)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when valid_masks? raises an error" do
|
110
|
+
let(:value) { "I am not correct" }
|
111
|
+
|
112
|
+
it "returns false" do
|
113
|
+
expect(described_class.alphanumerify(*masks)).to be_falsey
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# PRIVATE
|
119
|
+
describe "#valid_mask?" do
|
120
|
+
context "if mask.match(match_with) is not nil" do
|
121
|
+
let(:masks) { ["Apt. #" "##", "Banana Street No. ###"] }
|
122
|
+
let(:match_with) { /#/ }
|
123
|
+
|
124
|
+
it "returns true" do
|
125
|
+
expect(described_class.send(:valid_mask?, *masks, match_with)).to be_truthy
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "if mask is not equal to '#'" do
|
130
|
+
let(:masks) { ["###", "#" "abc @", "!"] }
|
131
|
+
let(:match_with) { /\?/ }
|
132
|
+
|
133
|
+
it "raises an error" do
|
134
|
+
expect { described_class.send(:valid_mask?, *masks, match_with) }.to raise_error
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Matchers
|
3
|
+
def have_valid_chinese_mobile
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
def have_valid_chinese_landline
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class PhoneNumberMatcher
|
12
|
+
def initialize(phone_number)
|
13
|
+
self.phone_number = phone_number
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches?(actual)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def description
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
def failure_message
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
def failure_message_when_negated
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def actual=(actual)
|
35
|
+
self.actual = actual
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :actual
|
39
|
+
attr_accessor :phone_number, :validator
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe DataMaker::ArrayUtilities do
|
4
|
+
let(:array_utilities) { described_class }
|
5
|
+
|
6
|
+
describe "#self.const_array" do
|
7
|
+
let(:self_const_array) { array_utilities.const_array(argument) }
|
8
|
+
let(:argument) { ["a".."z"] }
|
9
|
+
|
10
|
+
context "when the object is not an array" do
|
11
|
+
let(:argument) { "a".."z" }
|
12
|
+
|
13
|
+
it "converts it to an array" do
|
14
|
+
expect(self_const_array).to be_a(Array)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "freezes the array" do
|
19
|
+
array = self_const_array
|
20
|
+
expect(array.frozen?).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it "freezes the array elements" do
|
24
|
+
array = self_const_array
|
25
|
+
array.each do |a|
|
26
|
+
expect(a.frozen?).to be_truthy
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#self.random_pick" do
|
32
|
+
let(:random_pick) { array_utilities.random_pick(array, n) }
|
33
|
+
let(:array) { [*"a".."z"] }
|
34
|
+
let(:elements) { Set.new("a".."z") }
|
35
|
+
let(:n) { rand(1..5) }
|
36
|
+
|
37
|
+
it "randomly picks n number of elements" do
|
38
|
+
rand(1000..9999).times do
|
39
|
+
randomly_picked_elements = random_pick
|
40
|
+
expect(randomly_picked_elements.length).to eq(n)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it "randomly picks elements in the specified array" do
|
45
|
+
randomly_picked_elements = random_pick
|
46
|
+
rand(1000..9999).times do
|
47
|
+
randomly_picked_elements.each do |element|
|
48
|
+
expect(elements).to include(element)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#self.freeze_all" do
|
55
|
+
let(:freeze_all) { array_utilities.freeze_all(array) }
|
56
|
+
let(:array) { [*"a".."z"] }
|
57
|
+
|
58
|
+
it "freezes the array" do
|
59
|
+
array = freeze_all
|
60
|
+
expect(array.frozen?).to be_truthy
|
61
|
+
end
|
62
|
+
|
63
|
+
it "freezes the array elements" do
|
64
|
+
array = freeze_all
|
65
|
+
array.each do |a|
|
66
|
+
expect(a.frozen?).to be_truthy
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "#self.shuffle" do
|
72
|
+
let(:shuffle) { array_utilities.shuffle(array) }
|
73
|
+
let(:array) { [*"a".."z"] }
|
74
|
+
let(:elements) { Set.new("a".."z") }
|
75
|
+
|
76
|
+
it "shuffles the array" do
|
77
|
+
different_sort = 0
|
78
|
+
rand(1000..9999).times do
|
79
|
+
shuffled_array = shuffle
|
80
|
+
different_sort += 1 if shuffled_array != array
|
81
|
+
end
|
82
|
+
expect(different_sort).to satisfy { |value| value > 0 }
|
83
|
+
end
|
84
|
+
|
85
|
+
it "shuffles the array without adding/removing elements" do
|
86
|
+
rand(1000..9999).times do
|
87
|
+
shuffled_array = shuffle
|
88
|
+
expect(shuffled_array.to_set).to eq(elements)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe "#random_pick" do
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "#freeze_all" do
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#shuffle" do
|
100
|
+
end
|
101
|
+
end
|
File without changes
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
|
10
|
+
SimpleCov.start
|
11
|
+
|
12
|
+
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
|
13
|
+
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.expect_with :rspec do |expectations|
|
16
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
17
|
+
end
|
18
|
+
|
19
|
+
config.mock_with :rspec do |mocks|
|
20
|
+
mocks.verify_partial_doubles = true
|
21
|
+
end
|
22
|
+
|
23
|
+
begin
|
24
|
+
config.filter_run :focus
|
25
|
+
config.run_all_when_everything_filtered = true
|
26
|
+
|
27
|
+
config.disable_monkey_patching!
|
28
|
+
|
29
|
+
config.warnings = false
|
30
|
+
|
31
|
+
if config.files_to_run.one?
|
32
|
+
config.default_formatter = 'doc'
|
33
|
+
end
|
34
|
+
|
35
|
+
config.profile_examples = 10
|
36
|
+
|
37
|
+
config.order = :random
|
38
|
+
|
39
|
+
Kernel.srand config.seed
|
40
|
+
end
|
41
|
+
end
|