quick_shoulda 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +6 -0
- data/lib/generators/quick_shoulda/{g_generator.rb → g/g_generator.rb} +0 -0
- data/lib/generators/quick_shoulda/install/install_generator.rb +11 -0
- data/lib/generators/quick_shoulda/install/templates/.qshoulda.yml +1 -0
- data/lib/quick_shoulda.rb +0 -1
- data/lib/quick_shoulda/config_file_reader.rb +20 -0
- data/lib/quick_shoulda/main.rb +15 -2
- data/lib/quick_shoulda/version.rb +1 -1
- data/spec/config_file_reader_spec.rb +34 -0
- data/spec/main_spec.rb +40 -16
- metadata +10 -6
- data/lib/quick_shoulda/config.rb +0 -5
data/README.rdoc
CHANGED
@@ -62,8 +62,14 @@ multi model name / paths as parameter
|
|
62
62
|
or
|
63
63
|
Rails generate quick_shoulda:g app/models/user.rb app/models/post.rb
|
64
64
|
|
65
|
+
== Configurations
|
66
|
+
Install config file by
|
67
|
+
Rails generate quick_shoulda:install
|
65
68
|
|
69
|
+
This will place the .qshoulda.yml in the root path , then edit this file for configuration purpose
|
66
70
|
|
71
|
+
Config location to put the generated spec files
|
72
|
+
spec_folder: test/models
|
67
73
|
|
68
74
|
== Contributing
|
69
75
|
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
spec_folder: spec/models/
|
data/lib/quick_shoulda.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module QuickShoulda
|
4
|
+
module ConfigFileReader
|
5
|
+
class << self
|
6
|
+
def read
|
7
|
+
YAML.load(File.open(config_file_name))
|
8
|
+
end
|
9
|
+
|
10
|
+
def config_file_exist?
|
11
|
+
File.file?(config_file_name)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def config_file_name
|
16
|
+
'./.qshoulda.yml'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/quick_shoulda/main.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'quick_shoulda/config_file_reader'
|
2
|
+
|
1
3
|
module QuickShoulda
|
2
4
|
module Main
|
3
5
|
def self.included(base)
|
@@ -15,11 +17,22 @@ module QuickShoulda
|
|
15
17
|
|
16
18
|
def configure(path)
|
17
19
|
@path = path
|
18
|
-
@spec_folder =
|
20
|
+
@spec_folder = default_spec_folder
|
21
|
+
|
22
|
+
if ConfigFileReader.config_file_exist?
|
23
|
+
configs = ConfigFileReader.read
|
24
|
+
@spec_folder = configs['spec_folder'].dup if configs['spec_folder']
|
25
|
+
@spec_folder << "/" if @spec_folder[-1].to_s != '/'
|
26
|
+
end
|
27
|
+
|
19
28
|
@model_full_namespace = _model_full_namespace
|
20
29
|
@spec_file_path = _spec_file_path
|
21
30
|
end
|
22
31
|
|
32
|
+
def default_spec_folder
|
33
|
+
'spec/models/'
|
34
|
+
end
|
35
|
+
|
23
36
|
def generate
|
24
37
|
generate_shoulda_content
|
25
38
|
create_and_write_to_file
|
@@ -34,6 +47,6 @@ module QuickShoulda
|
|
34
47
|
create_file_and_write_init_content unless spec_file_exist?
|
35
48
|
clear_all_blocks
|
36
49
|
write_block(validations_block + associations_block)
|
37
|
-
end
|
50
|
+
end
|
38
51
|
end
|
39
52
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'QuickShoulda::ConfigFileReader' do
|
4
|
+
subject { QuickShoulda::ConfigFileReader }
|
5
|
+
describe '#config_file_exist?' do
|
6
|
+
context 'with config file' do
|
7
|
+
before { subject.stub(:config_file_name).and_return('./spec/spec_helper.rb') }
|
8
|
+
|
9
|
+
it 'should return true' do
|
10
|
+
subject.config_file_exist?.should be_true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'without config file' do
|
15
|
+
it 'should return false' do
|
16
|
+
subject.config_file_exist?.should be_false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#read' do
|
22
|
+
before { subject.stub(:config_file_name).and_return('./.travis.yml') }
|
23
|
+
|
24
|
+
it 'should return a hash of configurations' do
|
25
|
+
subject.read.should be_a Hash
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has string keys' do
|
29
|
+
subject.read.keys.each do |key|
|
30
|
+
key.should be_a String
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/main_spec.rb
CHANGED
@@ -47,35 +47,59 @@ describe 'QuickShoulda::Main' do
|
|
47
47
|
let(:validations) {[]}
|
48
48
|
let(:associations) {[]}
|
49
49
|
|
50
|
-
before do
|
51
|
-
send(:configure, given_path)
|
52
|
-
end
|
53
|
-
|
54
50
|
context 'path' do
|
55
51
|
it 'should store valid value' do
|
52
|
+
send(:configure, given_path)
|
56
53
|
path.should eq given_path
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
|
-
context '
|
61
|
-
|
62
|
-
spec_folder
|
57
|
+
context 'config file given' do
|
58
|
+
let(:configs) do
|
59
|
+
{ 'spec_folder' => 'aaaaaaaaaaaa' }
|
63
60
|
end
|
64
|
-
end
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
62
|
+
before do
|
63
|
+
QuickShoulda::ConfigFileReader.should_receive(:config_file_exist?).and_return(true)
|
64
|
+
QuickShoulda::ConfigFileReader.should_receive(:read).and_return(configs)
|
65
|
+
send(:configure, given_path)
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'spec_folder' do
|
69
|
+
it 'should get value from config file' do
|
70
|
+
send(:spec_folder).should == configs['spec_folder'] + '/'
|
71
|
+
end
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
73
|
-
context '
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
context 'config file is not given' do
|
76
|
+
before do
|
77
|
+
QuickShoulda::ConfigFileReader.should_receive(:config_file_exist?).and_return(false)
|
78
|
+
send(:configure, given_path)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
context 'spec_folder' do
|
83
|
+
it 'should store valid value' do
|
84
|
+
spec_folder.should eq send(:default_spec_folder)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'model_full_namespace' do
|
89
|
+
let(:expected) { ::User::Friend }
|
90
|
+
it 'should store valid value' do
|
91
|
+
model_full_namespace.should eq expected
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'spec_file_path' do
|
96
|
+
let(:expected) { 'spec/models/user/friend_spec.rb' }
|
97
|
+
it 'should store valid value' do
|
98
|
+
spec_file_path.should eq expected
|
99
|
+
end
|
77
100
|
end
|
78
101
|
end
|
102
|
+
|
79
103
|
end
|
80
104
|
|
81
105
|
describe '#generate' 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.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: random_string
|
@@ -77,9 +77,11 @@ files:
|
|
77
77
|
- LICENSE.txt
|
78
78
|
- README.rdoc
|
79
79
|
- Rakefile
|
80
|
-
- lib/generators/quick_shoulda/g_generator.rb
|
80
|
+
- lib/generators/quick_shoulda/g/g_generator.rb
|
81
|
+
- lib/generators/quick_shoulda/install/install_generator.rb
|
82
|
+
- lib/generators/quick_shoulda/install/templates/.qshoulda.yml
|
81
83
|
- lib/quick_shoulda.rb
|
82
|
-
- lib/quick_shoulda/
|
84
|
+
- lib/quick_shoulda/config_file_reader.rb
|
83
85
|
- lib/quick_shoulda/errors.rb
|
84
86
|
- lib/quick_shoulda/file_writer.rb
|
85
87
|
- lib/quick_shoulda/generator.rb
|
@@ -91,6 +93,7 @@ files:
|
|
91
93
|
- lib/quick_shoulda/path_resolver.rb
|
92
94
|
- lib/quick_shoulda/version.rb
|
93
95
|
- quick_shoulda.gemspec
|
96
|
+
- spec/config_file_reader_spec.rb
|
94
97
|
- spec/file_writer_spec.rb
|
95
98
|
- spec/fixtures/user_spec.rb
|
96
99
|
- spec/fixtures/write_spec.rb
|
@@ -118,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
121
|
version: '0'
|
119
122
|
segments:
|
120
123
|
- 0
|
121
|
-
hash: -
|
124
|
+
hash: -2794241305955949592
|
122
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
126
|
none: false
|
124
127
|
requirements:
|
@@ -127,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
130
|
version: '0'
|
128
131
|
segments:
|
129
132
|
- 0
|
130
|
-
hash: -
|
133
|
+
hash: -2794241305955949592
|
131
134
|
requirements: []
|
132
135
|
rubyforge_project:
|
133
136
|
rubygems_version: 1.8.25
|
@@ -135,6 +138,7 @@ signing_key:
|
|
135
138
|
specification_version: 3
|
136
139
|
summary: read through your model file and generate Shoulda test cases
|
137
140
|
test_files:
|
141
|
+
- spec/config_file_reader_spec.rb
|
138
142
|
- spec/file_writer_spec.rb
|
139
143
|
- spec/fixtures/user_spec.rb
|
140
144
|
- spec/fixtures/write_spec.rb
|