quick_shoulda 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +4 -2
- data/lib/quick_shoulda/generator/validation.rb +1 -1
- data/lib/quick_shoulda/version.rb +1 -1
- data/quick_shoulda.gemspec +1 -0
- data/spec/generator/validation_spec.rb +2 -2
- metadata +17 -5
- data/lib/quick_shoulda/random_string/data.rb +0 -31
- data/lib/quick_shoulda/random_string.rb +0 -53
- data/spec/random_string_spec.rb +0 -94
data/README.rdoc
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
= QuickShoulda
|
1
|
+
= QuickShoulda
|
2
|
+
{<img src="https://badge.fury.io/rb/quick_shoulda.png" alt="Gem Version" />}[http://badge.fury.io/rb/quick_shoulda]
|
3
|
+
{<img src="https://travis-ci.org/nqtien310/quick_shoulda.png?branch=master" alt="Build Status" />}[https://travis-ci.org/nqtien310/quick_shoulda]
|
2
4
|
|
3
5
|
A Rails generator which automatically generates Shoulda test cases ,
|
4
6
|
|
@@ -73,4 +75,4 @@ multi model name / paths as parameter
|
|
73
75
|
|
74
76
|
== Copyright
|
75
77
|
|
76
|
-
Copyright (c) 2013 nqtien310@gmail.com.
|
78
|
+
Copyright (c) 2013 nqtien310@gmail.com.
|
data/quick_shoulda.gemspec
CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency "random_string"
|
22
23
|
spec.add_development_dependency "debugger", "~> 1.3"
|
23
24
|
spec.add_development_dependency "rspec"
|
24
25
|
end
|
@@ -34,7 +34,7 @@ describe 'QuickShoulda::Generator::Validation' do
|
|
34
34
|
inclusion_validator, exclusion_validator, numericality_validator] }
|
35
35
|
let(:model) { mock(:model, validators: validators) }
|
36
36
|
|
37
|
-
before {
|
37
|
+
before { RandomString.should_receive(:generate).with(/abc/).and_return(random_strings) }
|
38
38
|
|
39
39
|
let(:expected) {
|
40
40
|
[
|
@@ -369,7 +369,7 @@ describe 'QuickShoulda::Generator::Validation' do
|
|
369
369
|
}
|
370
370
|
}
|
371
371
|
|
372
|
-
before {
|
372
|
+
before { RandomString.should_receive(:generate).with(options[:with]).and_return(random_strings) }
|
373
373
|
after { send(:generate_shouldas_for_format_validation, attr, options) }
|
374
374
|
|
375
375
|
it 'should invoke generate_allow_shouldas for matched_strings and unmatched strings' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quick_shoulda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,6 +11,22 @@ bindir: bin
|
|
11
11
|
cert_chain: []
|
12
12
|
date: 2013-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: random_string
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: debugger
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,8 +89,6 @@ files:
|
|
73
89
|
- lib/quick_shoulda/helpers/string_helpers.rb
|
74
90
|
- lib/quick_shoulda/main.rb
|
75
91
|
- lib/quick_shoulda/path_resolver.rb
|
76
|
-
- lib/quick_shoulda/random_string.rb
|
77
|
-
- lib/quick_shoulda/random_string/data.rb
|
78
92
|
- lib/quick_shoulda/version.rb
|
79
93
|
- quick_shoulda.gemspec
|
80
94
|
- spec/file_writer_spec.rb
|
@@ -87,7 +101,6 @@ files:
|
|
87
101
|
- spec/models/not_a_ruby_file.txt
|
88
102
|
- spec/path_resolver_spec.rb
|
89
103
|
- spec/quick_shoulda_spec.rb
|
90
|
-
- spec/random_string_spec.rb
|
91
104
|
- spec/spec_helper.rb
|
92
105
|
- spec/string_helpers_spec.rb
|
93
106
|
homepage: ''
|
@@ -126,6 +139,5 @@ test_files:
|
|
126
139
|
- spec/models/not_a_ruby_file.txt
|
127
140
|
- spec/path_resolver_spec.rb
|
128
141
|
- spec/quick_shoulda_spec.rb
|
129
|
-
- spec/random_string_spec.rb
|
130
142
|
- spec/spec_helper.rb
|
131
143
|
- spec/string_helpers_spec.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module QuickShoulda
|
2
|
-
module RandomString
|
3
|
-
module Data
|
4
|
-
StoredStrings = {
|
5
|
-
:Emails => ['us@gmail.com', 'us.vn@gmail.com', 'us_vn@gmail.com', 'us_vn@gmail.com.vn'],
|
6
|
-
:Urls => ['www.domain.com', 'www.domain.subdomain.com', 'http://www.domain.com', 'http://www.domain.subdomain.com',
|
7
|
-
'http://www.domain.com/path/1', 'https://www.domain.com', 'https://www.domain.subdomain.com', 'domain.subdomain.com',
|
8
|
-
'domain.com/path/1', 'subdomain.domain.com/path/1'],
|
9
|
-
:IPS => ['192.168.1.1', '192.168.1.2'],
|
10
|
-
:Sex => ['male', 'female', 'gay', 'les', 'other'],
|
11
|
-
:Zips => ['10001', '10002', '10003'],
|
12
|
-
:Phones => ['732-757-2923', '1732-757-2923', '+84 121731845', '84 121731845', '(84) 121731845'],
|
13
|
-
:Datetimes => ['1999-01-01', '99-01-01', '1999/01/01', '99/01/01', '01/01/99', '03/10/1986', '01-01-1999', '01-01-99', 'January 07, 2013',
|
14
|
-
'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday',
|
15
|
-
'january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december',
|
16
|
-
'am', 'pm'],
|
17
|
-
:Countries => ['Vietnam', 'America', 'England', 'Vietnamese', 'American', 'English'],
|
18
|
-
:Cities => ['New York', 'London', 'Ho Chi Minh'],
|
19
|
-
:Statuses => ['married', 'single', 'available', 'complicated'],
|
20
|
-
:Files => ['filename.txt', 'filename.jpg', 'filename.png', 'filename.jpeg'],
|
21
|
-
:Extensions => ['txt', 'jpg', 'png', 'jpeg', 'mp4', 'mp3', 'wmv'],
|
22
|
-
:Videos => ['filename.wmv', 'filename.mp4', 'filename.flv'],
|
23
|
-
:CCNumbers => ['4111 1111 1111 1111', '5500 0000 0000 0004', '3400 0000 0000 009', '3000 0000 0000 04'],
|
24
|
-
:CCodes => ['84', '1', '39'],
|
25
|
-
:ISOCCodes => ['US', 'USA', 'VN', 'VNM'],
|
26
|
-
:Services => ['yahoo', 'google', 'facebook', 'amazone', 'youtube', 'paypal', 'alchemy'],
|
27
|
-
:Marks => ['excellent', 'good', 'bad']
|
28
|
-
}
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'quick_shoulda/random_string/data'
|
2
|
-
|
3
|
-
module QuickShoulda
|
4
|
-
module RandomString
|
5
|
-
class << self
|
6
|
-
Size = 3
|
7
|
-
LowerCaseChars = ('a'..'z').to_a
|
8
|
-
UpperCaseChars = ('A'..'Z').to_a
|
9
|
-
Digits = (0..9).to_a
|
10
|
-
|
11
|
-
def sample_strings
|
12
|
-
stored_strings + random_digits_strings + random_chars_strings
|
13
|
-
end
|
14
|
-
|
15
|
-
def stored_strings
|
16
|
-
@stored_strings ||= Data::StoredStrings.values.flatten
|
17
|
-
end
|
18
|
-
|
19
|
-
def random_digits_strings
|
20
|
-
random_strings(Digits)
|
21
|
-
end
|
22
|
-
|
23
|
-
def random_chars_strings
|
24
|
-
random_strings(LowerCaseChars + UpperCaseChars)
|
25
|
-
end
|
26
|
-
|
27
|
-
def random_strings(base)
|
28
|
-
(1..50).map { |length| length.times.inject('') { |initial, n| initial + base[rand(10)].to_s } }
|
29
|
-
end
|
30
|
-
|
31
|
-
def generate(pattern)
|
32
|
-
matched_strings = []
|
33
|
-
unmatched_strings = []
|
34
|
-
RandomString.sample_strings.each do |sample_string|
|
35
|
-
break if matched_strings.size == Size && unmatched_strings.size == Size
|
36
|
-
|
37
|
-
if sample_string =~ pattern
|
38
|
-
matched_strings << sample_string if matched_strings.size < Size
|
39
|
-
else
|
40
|
-
unmatched_strings << sample_string if unmatched_strings.size < Size
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
{
|
45
|
-
matched_strings: matched_strings,
|
46
|
-
unmatched_strings: unmatched_strings
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
alias_method :gen, :generate
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
data/spec/random_string_spec.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe "QuickShoulda::RandomString" do
|
4
|
-
subject { QuickShoulda::RandomString }
|
5
|
-
|
6
|
-
describe ".stored_strings" do
|
7
|
-
it 'should return an array of string' do
|
8
|
-
subject.stored_strings.should be_an Array
|
9
|
-
subject.stored_strings.should_not be_empty
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '.random_digits' do
|
14
|
-
it 'should return array of different length digits' do
|
15
|
-
random_digits = subject.random_digits_strings
|
16
|
-
random_digits.should be_an Array
|
17
|
-
random_digits.each do |random_str|
|
18
|
-
(random_str =~ /[0-9]+/).should_not be_nil
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe '.random_chars' do
|
24
|
-
it 'should return array of different length characters' do
|
25
|
-
random_chars = subject.random_chars_strings
|
26
|
-
random_chars.should be_an Array
|
27
|
-
random_chars.each do |random_str|
|
28
|
-
(random_str =~ /[a-zA-Z]+/).should_not be_nil
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#generate' do
|
34
|
-
let(:pattern) { /^[a-z0-9_\.]+@[a-z]+\.[a-z]+$/i }
|
35
|
-
|
36
|
-
before { subject.should_receive(:sample_strings).and_return(sample_strings) }
|
37
|
-
context 'only matches strings' do
|
38
|
-
let(:sample_strings) {
|
39
|
-
[
|
40
|
-
'nqtien310@gmail.com',
|
41
|
-
'nqtien310@hotdev.com'
|
42
|
-
]
|
43
|
-
}
|
44
|
-
let(:expected) do
|
45
|
-
{
|
46
|
-
matched_strings: sample_strings,
|
47
|
-
unmatched_strings: []
|
48
|
-
}
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should return matches string' do
|
52
|
-
subject.gen(pattern).should eq expected
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context 'only unmatched strings' do
|
57
|
-
let(:sample_strings) {
|
58
|
-
[
|
59
|
-
'nqtien310',
|
60
|
-
'nqtien310'
|
61
|
-
]
|
62
|
-
}
|
63
|
-
let(:expected) do
|
64
|
-
{
|
65
|
-
matched_strings: [],
|
66
|
-
unmatched_strings: sample_strings
|
67
|
-
}
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should return matches string' do
|
71
|
-
subject.gen(pattern).should eq expected
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
context 'both matched and unmatched strings' do
|
76
|
-
let(:sample_strings) {
|
77
|
-
[
|
78
|
-
'nqtien310@gmail.com',
|
79
|
-
'nqtien310'
|
80
|
-
]
|
81
|
-
}
|
82
|
-
let(:expected) do
|
83
|
-
{
|
84
|
-
matched_strings: ['nqtien310@gmail.com'],
|
85
|
-
unmatched_strings: ['nqtien310']
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should return matches string' do
|
90
|
-
subject.gen(pattern).should eq expected
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|