quick_shoulda 0.0.5 → 0.0.6
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 -0
- data/lib/generators/quick_shoulda/g_generator.rb +2 -1
- data/lib/quick_shoulda/config.rb +5 -0
- data/lib/quick_shoulda/main.rb +4 -4
- data/lib/quick_shoulda/version.rb +1 -1
- data/lib/quick_shoulda.rb +8 -3
- data/spec/main_spec.rb +7 -22
- data/spec/quick_shoulda_spec.rb +27 -19
- metadata +2 -1
data/README.rdoc
CHANGED
data/lib/quick_shoulda/main.rb
CHANGED
@@ -6,16 +6,16 @@ module QuickShoulda
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
def configure_and_generate(path
|
10
|
-
configure(path
|
9
|
+
def configure_and_generate(path)
|
10
|
+
configure(path)
|
11
11
|
generate
|
12
12
|
end
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def configure(path
|
16
|
+
def configure(path)
|
17
17
|
@path = path
|
18
|
-
@spec_folder =
|
18
|
+
@spec_folder = QuickShoulda::Config::SpecFolder
|
19
19
|
@model_full_namespace = _model_full_namespace
|
20
20
|
@spec_file_path = _spec_file_path
|
21
21
|
end
|
data/lib/quick_shoulda.rb
CHANGED
@@ -4,6 +4,7 @@ require "quick_shoulda/path_resolver"
|
|
4
4
|
require "quick_shoulda/file_writer"
|
5
5
|
require "quick_shoulda/generator"
|
6
6
|
require "quick_shoulda/main"
|
7
|
+
require "quick_shoulda/config"
|
7
8
|
require 'fileutils'
|
8
9
|
|
9
10
|
module QuickShoulda
|
@@ -15,15 +16,19 @@ module QuickShoulda
|
|
15
16
|
include Main
|
16
17
|
include Errors
|
17
18
|
|
18
|
-
def process(
|
19
|
-
raise PathNotGivenError
|
19
|
+
def process(paths)
|
20
|
+
raise PathNotGivenError if paths.empty?
|
21
|
+
paths.each { |path| _process(path) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def _process(path)
|
20
25
|
unless is_a_constant?(path)
|
21
26
|
raise NotAModelPathError unless path =~ /models\//
|
22
27
|
raise FileDoesNotExistError unless File.file?(path)
|
23
28
|
raise NotRubyFileError unless File.extname(path) == '.rb'
|
24
29
|
end
|
25
30
|
|
26
|
-
configure_and_generate(path
|
31
|
+
configure_and_generate(path)
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
data/spec/main_spec.rb
CHANGED
@@ -32,24 +32,23 @@ describe 'QuickShoulda::Main' do
|
|
32
32
|
include QuickShoulda::Main
|
33
33
|
|
34
34
|
let(:path) { 'path' }
|
35
|
-
let(:spec_folder) { 'spec/models/' }
|
36
35
|
|
37
36
|
it 'should invoke configure and generate' do
|
38
|
-
should_receive(:configure).with(path
|
37
|
+
should_receive(:configure).with(path)
|
39
38
|
should_receive(:generate)
|
40
|
-
configure_and_generate(path
|
39
|
+
configure_and_generate(path)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
44
43
|
describe '#configure' do
|
45
44
|
include QuickShoulda::Main
|
45
|
+
|
46
46
|
let(:given_path) { 'models/user/friend.rb' }
|
47
|
-
let(:given_spec_folder) { 'spec/models' }
|
48
47
|
let(:validations) {[]}
|
49
48
|
let(:associations) {[]}
|
50
49
|
|
51
50
|
before do
|
52
|
-
send(:configure,given_path
|
51
|
+
send(:configure, given_path)
|
53
52
|
end
|
54
53
|
|
55
54
|
context 'path' do
|
@@ -58,24 +57,10 @@ describe 'QuickShoulda::Main' do
|
|
58
57
|
end
|
59
58
|
end
|
60
59
|
|
61
|
-
context 'spec_folder' do
|
62
|
-
|
63
|
-
|
64
|
-
context 'with suffix slash' do
|
65
|
-
let(:given_spec_folder) { 'spec/models/' }
|
66
|
-
it 'should store valid value' do
|
67
|
-
spec_folder.should eq expected
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context 'without suffix slash' do
|
72
|
-
let(:given_spec_folder) { 'spec/models' }
|
73
|
-
|
74
|
-
it 'should store valid value' do
|
75
|
-
spec_folder.should eq expected
|
76
|
-
end
|
60
|
+
context 'spec_folder' do
|
61
|
+
it 'should store valid value' do
|
62
|
+
spec_folder.should eq QuickShoulda::Config::SpecFolder
|
77
63
|
end
|
78
|
-
|
79
64
|
end
|
80
65
|
|
81
66
|
context 'model_full_namespace' do
|
data/spec/quick_shoulda_spec.rb
CHANGED
@@ -7,41 +7,49 @@ module User
|
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'QuickShoulda' do
|
10
|
-
describe '#process' do
|
11
|
-
|
10
|
+
describe '#process' do
|
11
|
+
describe 'paths is empty' do
|
12
|
+
it 'should raise QuickShoulda::Errors::PathNotGivenError' do
|
13
|
+
expect {
|
14
|
+
QuickShoulda.process([])
|
15
|
+
}.to raise_error(QuickShoulda::Errors::PathNotGivenError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe 'paths is not empty' do
|
20
|
+
let(:paths) { ['User', 'app/models/user.rb'] }
|
21
|
+
it 'should invoke _process for each path' do
|
22
|
+
paths.each { |path| QuickShoulda.should_receive(:_process).with(path) }
|
23
|
+
QuickShoulda.process(paths)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
12
27
|
|
28
|
+
describe '#_process' do
|
13
29
|
describe 'all valid' do
|
14
30
|
let(:path) { 'models/user/friend.rb' }
|
15
31
|
before { File.should_receive(:file?).with(path).once.and_return(true) }
|
16
32
|
|
17
33
|
context 'with spec_folder given' do
|
18
34
|
it 'invoke Main::configure_and_generate with given spec_folder' do
|
19
|
-
QuickShoulda.should_receive(:configure_and_generate).with(path
|
20
|
-
QuickShoulda.
|
35
|
+
QuickShoulda.should_receive(:configure_and_generate).with(path)
|
36
|
+
QuickShoulda._process(path)
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
24
40
|
context 'without spec_folder given' do
|
25
41
|
it 'invoke Main::configure_and_generate with default spec_folder' do
|
26
|
-
QuickShoulda.should_receive(:configure_and_generate).with(path
|
27
|
-
QuickShoulda.
|
42
|
+
QuickShoulda.should_receive(:configure_and_generate).with(path)
|
43
|
+
QuickShoulda._process(path)
|
28
44
|
end
|
29
45
|
end
|
30
46
|
end
|
31
47
|
|
32
48
|
context 'path is given' do
|
33
|
-
describe 'path is nil' do
|
34
|
-
it 'should raise QuickShoulda::Errors::PathNotGivenError' do
|
35
|
-
expect {
|
36
|
-
QuickShoulda.process(nil)
|
37
|
-
}.to raise_error(QuickShoulda::Errors::PathNotGivenError)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
49
|
describe 'path does not contain "models/"' do
|
42
50
|
it 'should raise QuickShoulda::Errors::NotAModelPathError' do
|
43
51
|
expect {
|
44
|
-
QuickShoulda.
|
52
|
+
QuickShoulda._process("not/contain/model/s")
|
45
53
|
}.to raise_error(QuickShoulda::Errors::NotAModelPathError)
|
46
54
|
end
|
47
55
|
end
|
@@ -49,7 +57,7 @@ describe 'QuickShoulda' do
|
|
49
57
|
describe 'file does not exist' do
|
50
58
|
it 'should raise QuickShoulda::Errors::FileDoesNotExistError' do
|
51
59
|
expect {
|
52
|
-
QuickShoulda.
|
60
|
+
QuickShoulda._process("models/nothere.rb")
|
53
61
|
}.to raise_error(QuickShoulda::Errors::FileDoesNotExistError)
|
54
62
|
end
|
55
63
|
end
|
@@ -57,7 +65,7 @@ describe 'QuickShoulda' do
|
|
57
65
|
describe 'not a ruby file' do
|
58
66
|
it 'should raise QuickShoulda::Errors::NotRubyFileError' do
|
59
67
|
expect {
|
60
|
-
QuickShoulda.
|
68
|
+
QuickShoulda._process("models/not_a_ruby_file.txt")
|
61
69
|
}.to raise_error(QuickShoulda::Errors::FileDoesNotExistError)
|
62
70
|
end
|
63
71
|
end
|
@@ -67,8 +75,8 @@ describe 'QuickShoulda' do
|
|
67
75
|
let(:constant) { "User::Name" }
|
68
76
|
|
69
77
|
it 'should not raise any exception' do
|
70
|
-
QuickShoulda.should_receive(:configure_and_generate).with(constant
|
71
|
-
expect { QuickShoulda.
|
78
|
+
QuickShoulda.should_receive(:configure_and_generate).with(constant)
|
79
|
+
expect { QuickShoulda._process(constant) }.not_to raise_error
|
72
80
|
end
|
73
81
|
end
|
74
82
|
end
|
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.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/generators/quick_shoulda/g_generator.rb
|
65
65
|
- lib/generators/quick_shoulda/generate_generator.rb
|
66
66
|
- lib/quick_shoulda.rb
|
67
|
+
- lib/quick_shoulda/config.rb
|
67
68
|
- lib/quick_shoulda/errors.rb
|
68
69
|
- lib/quick_shoulda/file_writer.rb
|
69
70
|
- lib/quick_shoulda/generator.rb
|