quick_shoulda 0.0.2

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/spec/main_spec.rb ADDED
@@ -0,0 +1,154 @@
1
+ require 'spec_helper'
2
+ module User
3
+ module Friend
4
+
5
+ end
6
+ end
7
+
8
+ describe 'QuickShoulda::Main' do
9
+ include QuickShoulda::Generator
10
+ include QuickShoulda::PathResolver
11
+ include QuickShoulda::FileWriter
12
+
13
+ describe 'included' do
14
+ ['path', 'spec_folder', 'model_full_namespace', 'spec_file_path', 'validations_block', 'associations_block'].each do |var|
15
+ context "Before included" do
16
+ it "should not understand #{var}" do
17
+ expect { eval(var) }.to raise_error(NameError)
18
+ end
19
+ end
20
+
21
+ context "After included" do
22
+ include QuickShoulda::Main
23
+
24
+ it "should understand #{var}" do
25
+ eval(var).should be_nil
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#configure_and_generate' do
32
+ include QuickShoulda::Main
33
+
34
+ let(:path) { 'path' }
35
+ let(:spec_folder) { 'spec/models/' }
36
+
37
+ it 'should invoke configure and generate' do
38
+ should_receive(:configure).with(path, spec_folder)
39
+ should_receive(:generate)
40
+ configure_and_generate(path, spec_folder)
41
+ end
42
+ end
43
+
44
+ describe '#configure' do
45
+ include QuickShoulda::Main
46
+ let(:given_path) { 'models/user/friend.rb' }
47
+ let(:given_spec_folder) { 'spec/models' }
48
+ let(:validations) {[]}
49
+ let(:associations) {[]}
50
+
51
+ before do
52
+ send(:configure,given_path, given_spec_folder)
53
+ end
54
+
55
+ context 'path' do
56
+ it 'should store valid value' do
57
+ path.should eq given_path
58
+ end
59
+ end
60
+
61
+ context 'spec_folder' do
62
+ let(:expected) { 'spec/models/' }
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
77
+ end
78
+
79
+ end
80
+
81
+ context 'model_full_namespace' do
82
+ let(:expected) { ::User::Friend }
83
+ it 'should store valid value' do
84
+ model_full_namespace.should eq expected
85
+ end
86
+ end
87
+
88
+ context 'spec_file_path' do
89
+ let(:expected) { 'spec/models/user/friend_spec.rb' }
90
+ it 'should store valid value' do
91
+ spec_file_path.should eq expected
92
+ end
93
+ end
94
+ end
95
+
96
+ describe '#generate' do
97
+ include QuickShoulda::Main
98
+
99
+ it 'should invoke generate_shoulda_content and create_and_write_to_file' do
100
+ should_receive(:generate_shoulda_content)
101
+ should_receive(:create_and_write_to_file)
102
+ send(:generate)
103
+ end
104
+ end
105
+
106
+ describe '#generate_shoulda_content' do
107
+ include QuickShoulda::Main
108
+
109
+ let(:mfn) { "User::Friend" }
110
+ let(:validations) { [] }
111
+
112
+ before do
113
+ should_receive(:model_full_namespace).twice.and_return(mfn)
114
+ end
115
+
116
+ it 'should invoke shoulda_content on each generate block' do
117
+ should_receive(:generate_validations).with(mfn).and_return([])
118
+ should_receive(:shoulda_content).once.with(:validation, [])
119
+
120
+ should_receive(:generate_associations).with(mfn).and_return([])
121
+ should_receive(:shoulda_content).once.with(:association, [])
122
+ send(:generate_shoulda_content)
123
+ end
124
+ end
125
+
126
+ describe 'create_and_write_to_file' do
127
+ include QuickShoulda::Main
128
+
129
+ #should receive clear_all_blocks
130
+ #should receive write block with validations_block and associations_block
131
+ before do
132
+ should_receive(:validations_block).and_return("1")
133
+ should_receive(:associations_block).and_return("2")
134
+ should_receive(:clear_all_blocks)
135
+ should_receive(:write_block).with("12")
136
+ end
137
+
138
+ context 'spec_file_path does not exist' do
139
+ before { should_receive(:spec_file_exist?).and_return(false) }
140
+ it 'should invoke create_file_and_write_init_content' do
141
+ should_receive(:create_file_and_write_init_content)
142
+ create_and_write_to_file
143
+ end
144
+ end
145
+
146
+ context 'spec_file_path exists' do
147
+ before { should_receive(:spec_file_exist?).and_return(true) }
148
+ it 'should not invoke create_file_and_write_init_content' do
149
+ should_not_receive(:create_file_and_write_init_content)
150
+ create_and_write_to_file
151
+ end
152
+ end
153
+ end
154
+ end
File without changes
@@ -0,0 +1,88 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'QuickShoulda::PathResolver' do
4
+ include QuickShoulda::Main
5
+ include QuickShoulda::PathResolver
6
+ before do
7
+ @path = path
8
+ @spec_folder = 'spec/'
9
+ end
10
+
11
+ describe '_model_full_namespace_in_str' do
12
+ context 'valid path' do
13
+ context 'without namespace' do
14
+ let(:path) { '/models/user_account'}
15
+
16
+ context 'with .rb' do
17
+ it 'should return valid model name' do
18
+ _model_full_namespace_in_str.should eq 'UserAccount'
19
+ end
20
+ end
21
+
22
+ context 'without .rb' do
23
+ before { path = "#{path}.rb" }
24
+ it 'should return valid model name' do
25
+ _model_full_namespace_in_str.should eq 'UserAccount'
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'with namespace' do
31
+ let(:path) { 'models/user/friend.rb' }
32
+ it 'should return valid model name with namespace' do
33
+ _model_full_namespace_in_str.should eq 'User::Friend'
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ describe '_model_full_namespace' do
40
+ let(:model) { 'QuickShoulda::StringHelpers' }
41
+ before { should_receive(:_model_full_namespace_in_str).and_return(model) }
42
+
43
+ it 'should return constant' do
44
+ _model_full_namespace.should eq ::QuickShoulda::StringHelpers
45
+ end
46
+ end
47
+
48
+ context '_spec_file_path' do
49
+ before { File.stub(:file?).and_return(true) }
50
+ context 'valid file path' do
51
+ context 'without namespace' do
52
+ let(:path) { 'models/user.rb' }
53
+ let(:expected) { 'spec/user_spec.rb' }
54
+
55
+ it 'should return valid test file path' do
56
+ _spec_file_path.should eq expected
57
+ end
58
+ end
59
+
60
+ context 'with namespace' do
61
+ let(:path) { 'models/friendly/user.rb' }
62
+ let(:expected) { 'spec/friendly/user_spec.rb'}
63
+
64
+ it 'should return valid test file path' do
65
+ _spec_file_path.should eq expected
66
+ end
67
+ end
68
+
69
+ context 'with slash at beginning of file path' do
70
+ let(:path) { '/models/friendly/user.rb' }
71
+ let(:expected) { 'spec/friendly/user_spec.rb'}
72
+
73
+ it 'should return valid test file path' do
74
+ _spec_file_path.should eq expected
75
+ end
76
+ end
77
+
78
+ context 'without .rb' do
79
+ let(:path) { 'models/friendly/user' }
80
+ let(:expected) { 'spec/friendly/user_spec.rb'}
81
+
82
+ it 'should return valid test file path' do
83
+ _spec_file_path.should eq expected
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module User
4
+ module Friend
5
+
6
+ end
7
+ end
8
+
9
+ describe 'QuickShoulda' do
10
+ describe '#process' do
11
+ describe 'all valid' do
12
+ let(:path) { 'models/user/friend.rb' }
13
+ before { File.should_receive(:file?).with(path).once.and_return(true) }
14
+
15
+ context 'with spec_folder given' do
16
+ let(:spec_folder) { 'spec/models/' }
17
+ it 'invoke Main::configure_and_generate with given spec_folder' do
18
+ QuickShoulda.should_receive(:configure_and_generate).with(path, spec_folder)
19
+ QuickShoulda.process(path, spec_folder)
20
+ end
21
+ end
22
+
23
+ context 'without spec_folder given' do
24
+ it 'invoke Main::configure_and_generate with default spec_folder' do
25
+ QuickShoulda.should_receive(:configure_and_generate).with(path, 'spec/models/')
26
+ QuickShoulda.process(path)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ describe 'path is nil' do
33
+ it 'should raise QuickShoulda::Errors::PathNotGivenError' do
34
+ expect {
35
+ QuickShoulda.process(nil)
36
+ }.to raise_error(QuickShoulda::Errors::PathNotGivenError)
37
+ end
38
+ end
39
+
40
+ describe 'path does not contain "models/"' do
41
+ it 'should raise QuickShoulda::Errors::NotAModelPathError' do
42
+ expect {
43
+ QuickShoulda.process("not/contain/model/s")
44
+ }.to raise_error(QuickShoulda::Errors::NotAModelPathError)
45
+ end
46
+ end
47
+
48
+ describe 'file does not exist' do
49
+ it 'should raise QuickShoulda::Errors::FileDoesNotExistError' do
50
+ expect {
51
+ QuickShoulda.process("models/nothere.rb")
52
+ }.to raise_error(QuickShoulda::Errors::FileDoesNotExistError)
53
+ end
54
+ end
55
+
56
+ describe 'not a ruby file' do
57
+ it 'should raise QuickShoulda::Errors::NotRubyFileError' do
58
+ expect {
59
+ QuickShoulda.process("models/not_a_ruby_file.txt")
60
+ }.to raise_error(QuickShoulda::Errors::FileDoesNotExistError)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,93 @@
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
+ end
10
+ end
11
+
12
+ describe '.random_digits' do
13
+ it 'should return array of different length digits' do
14
+ random_digits = subject.random_digits_strings
15
+ random_digits.should be_an Array
16
+ random_digits.each do |random_str|
17
+ (random_str =~ /[0-9]+/).should_not be_nil
18
+ end
19
+ end
20
+ end
21
+
22
+ describe '.random_chars' do
23
+ it 'should return array of different length characters' do
24
+ random_chars = subject.random_chars_strings
25
+ random_chars.should be_an Array
26
+ random_chars.each do |random_str|
27
+ (random_str =~ /[a-zA-Z]+/).should_not be_nil
28
+ end
29
+ end
30
+ end
31
+
32
+ describe '#generate' do
33
+ let(:pattern) { /^[a-z0-9_\.]+@[a-z]+\.[a-z]+$/i }
34
+
35
+ before { subject.should_receive(:sample_strings).and_return(sample_strings) }
36
+ context 'only matches strings' do
37
+ let(:sample_strings) {
38
+ [
39
+ 'nqtien310@gmail.com',
40
+ 'nqtien310@hotdev.com'
41
+ ]
42
+ }
43
+ let(:expected) do
44
+ {
45
+ matched_strings: sample_strings,
46
+ unmatched_strings: []
47
+ }
48
+ end
49
+
50
+ it 'should return matches string' do
51
+ subject.gen(pattern).should eq expected
52
+ end
53
+ end
54
+
55
+ context 'only unmatched strings' do
56
+ let(:sample_strings) {
57
+ [
58
+ 'nqtien310',
59
+ 'nqtien310'
60
+ ]
61
+ }
62
+ let(:expected) do
63
+ {
64
+ matched_strings: [],
65
+ unmatched_strings: sample_strings
66
+ }
67
+ end
68
+
69
+ it 'should return matches string' do
70
+ subject.gen(pattern).should eq expected
71
+ end
72
+ end
73
+
74
+ context 'both matched and unmatched strings' do
75
+ let(:sample_strings) {
76
+ [
77
+ 'nqtien310@gmail.com',
78
+ 'nqtien310'
79
+ ]
80
+ }
81
+ let(:expected) do
82
+ {
83
+ matched_strings: ['nqtien310@gmail.com'],
84
+ unmatched_strings: ['nqtien310']
85
+ }
86
+ end
87
+
88
+ it 'should return matches string' do
89
+ subject.gen(pattern).should eq expected
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'quick_shoulda'
5
+
6
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
7
+ #
8
+ # RSpec.configure do |config|
9
+ # config.include FixtureContent
10
+ # end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'QuickShoulda::StringHelpers' do
4
+ include QuickShoulda::StringHelpers
5
+
6
+ describe '#value_transform' do
7
+ context 'string value' do
8
+ let(:value) { 'value' }
9
+ let(:expected) { "('value')"}
10
+
11
+ it 'should return value wrapped inside single quotes' do
12
+ value_transform(value).should eq expected
13
+ end
14
+ end
15
+
16
+ context 'symbol value' do
17
+ let(:value) { :value }
18
+ let(:expected) { "(:value)"}
19
+
20
+ it 'should return symbol value' do
21
+ value_transform(value).should eq expected
22
+ end
23
+ end
24
+
25
+ context 'other types of value' do
26
+ let(:value) { %w{a b c} }
27
+ let(:expected) { '(["a", "b", "c"])'}
28
+
29
+ it 'should return symbol value' do
30
+ value_transform(value).should eq expected
31
+ end
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quick_shoulda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tien Nguyen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: debugger
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Generate Shoulda testcases through rails generators
47
+ email:
48
+ - nqtien310@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rdebugrc
55
+ - .rspec
56
+ - .rvmrc
57
+ - Gemfile
58
+ - LICENSE.txt
59
+ - README.md
60
+ - Rakefile
61
+ - data/stored_strings.yml
62
+ - lib/generators/quick_shoulda/generate/generate_generator.rb
63
+ - lib/quick_shoulda.rb
64
+ - lib/quick_shoulda/errors.rb
65
+ - lib/quick_shoulda/file_writer.rb
66
+ - lib/quick_shoulda/generator.rb
67
+ - lib/quick_shoulda/generator/association.rb
68
+ - lib/quick_shoulda/generator/spec_content.rb
69
+ - lib/quick_shoulda/generator/validation.rb
70
+ - lib/quick_shoulda/helpers/string_helpers.rb
71
+ - lib/quick_shoulda/main.rb
72
+ - lib/quick_shoulda/path_resolver.rb
73
+ - lib/quick_shoulda/random_string.rb
74
+ - lib/quick_shoulda/version.rb
75
+ - quick_shoulda.gemspec
76
+ - spec/file_writer_spec.rb
77
+ - spec/fixtures/user_spec.rb
78
+ - spec/fixtures/write_spec.rb
79
+ - spec/generator/association_spec.rb
80
+ - spec/generator/spec_content_spec.rb
81
+ - spec/generator/validation_spec.rb
82
+ - spec/main_spec.rb
83
+ - spec/models/not_a_ruby_file.txt
84
+ - spec/path_resolver_spec.rb
85
+ - spec/quick_shoulda_spec.rb
86
+ - spec/random_string_spec.rb
87
+ - spec/spec_helper.rb
88
+ - spec/string_helpers_spec.rb
89
+ homepage: ''
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.25
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Generate Shoulda testcases
114
+ test_files:
115
+ - spec/file_writer_spec.rb
116
+ - spec/fixtures/user_spec.rb
117
+ - spec/fixtures/write_spec.rb
118
+ - spec/generator/association_spec.rb
119
+ - spec/generator/spec_content_spec.rb
120
+ - spec/generator/validation_spec.rb
121
+ - spec/main_spec.rb
122
+ - spec/models/not_a_ruby_file.txt
123
+ - spec/path_resolver_spec.rb
124
+ - spec/quick_shoulda_spec.rb
125
+ - spec/random_string_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/string_helpers_spec.rb