auto_specs 0.0.1.alpha → 0.0.1.alpha.1
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.
- checksums.yaml +4 -4
- data/README.md +3 -6
- data/auto_specs.gemspec +1 -1
- data/lib/auto_specs/active_record/validations/helpers/general_methods.rb +34 -0
- data/lib/auto_specs/active_record/validations/helpers/inclusion_methods.rb +14 -0
- data/lib/auto_specs/active_record/validations/helpers/length_methods.rb +30 -0
- data/lib/auto_specs/active_record/validations/helpers/numericality_methods.rb +30 -0
- data/lib/auto_specs/active_record/validations/mapping.rb +15 -0
- data/lib/auto_specs/active_record/validations/spec_builder.rb +43 -0
- data/lib/auto_specs/generators/model.rb +7 -2
- data/lib/auto_specs/version.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d731dc2b8f930cbed569b6d1e4f12eb09a027c8
|
4
|
+
data.tar.gz: 9703773fd6552a2cd7f222a4c467b5e4ca38fd60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b1caa6a30530c35800016f5a6ac590531d7d50a812683602813af62273df2ea206bae5f008702ccbdd367c0aa8e12766f152970f351b33abca0d8459772b200
|
7
|
+
data.tar.gz: e8944c624ceb733ebaa70c000f09cecc37f63a7167e132600bbd1f4923116dc59e3951d19711d259245d4a21b9a4d8e7fe45481f1832356ad1ff4b602e23a1f3
|
data/README.md
CHANGED
@@ -15,9 +15,6 @@ In order to use this gem, the following steps needs to be done before installing
|
|
15
15
|
|
16
16
|
The reason we chose `rspec` and `shoulda-matcher` is due to their simple and efficient DSL which makes writing tests easier.
|
17
17
|
|
18
|
-
### Currently we are generating the `associations` but it is being planned for `validations` too. There is an [open issue](https://github.com/aditya-kapoor/auto-specs/issues/5) for this.
|
19
|
-
|
20
|
-
|
21
18
|
## Installation
|
22
19
|
|
23
20
|
Add this line to your application's Gemfile:
|
@@ -38,10 +35,10 @@ Or install it yourself as:
|
|
38
35
|
|
39
36
|
Upon installation in the rails app, the gem presents you with two `rake` tasks namely:
|
40
37
|
|
41
|
-
1. auto_specs:
|
42
|
-
2. auto_spec:
|
38
|
+
1. auto_specs:models
|
39
|
+
2. auto_spec:controllers [TODO]
|
43
40
|
|
44
|
-
Running `rake auto_specs:
|
41
|
+
Running `rake auto_specs:models` would generate the model file specs in the `spec` directory.
|
45
42
|
|
46
43
|
## Contributing
|
47
44
|
|
data/auto_specs.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Aditya Kapoor"]
|
10
10
|
spec.email = ["aditya.kapoor@vinsol.com"]
|
11
11
|
spec.summary = "Adds certain tasks that would automatically generate some specs for you."
|
12
|
-
spec.description = ""
|
12
|
+
spec.description = "Don't Write Specs Yourself."
|
13
13
|
spec.homepage = "https://github.com/aditya-kapoor/auto-specs"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module AutoSpecs
|
2
|
+
module ActiveRecord
|
3
|
+
module Validations
|
4
|
+
module Helpers
|
5
|
+
module GeneralMethods
|
6
|
+
private
|
7
|
+
def on_option
|
8
|
+
"on(:#{ options[:on] })"
|
9
|
+
end
|
10
|
+
|
11
|
+
def message_option
|
12
|
+
"with_message('#{ options[:message] }')"
|
13
|
+
end
|
14
|
+
|
15
|
+
def scope_option
|
16
|
+
"scoped_to(:#{ options[:scope] })"
|
17
|
+
end
|
18
|
+
|
19
|
+
def case_sensitive_option
|
20
|
+
options[:case_sensitive] ? "case_sensitive" : "case_insensitive"
|
21
|
+
end
|
22
|
+
|
23
|
+
def allow_nil_option
|
24
|
+
"allow_nil"
|
25
|
+
end
|
26
|
+
|
27
|
+
def allow_blank_option
|
28
|
+
"allow_blank"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module AutoSpecs
|
2
|
+
module ActiveRecord
|
3
|
+
module Validations
|
4
|
+
module Helpers
|
5
|
+
module LengthMethods
|
6
|
+
private
|
7
|
+
def minimum_option
|
8
|
+
"is_at_least(#{ options[:minimum] })"
|
9
|
+
end
|
10
|
+
|
11
|
+
def maximum_option
|
12
|
+
"is_at_most(#{ options[:maximum] })"
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_option
|
16
|
+
"is_equal_to(#{ options[:is] })"
|
17
|
+
end
|
18
|
+
|
19
|
+
def too_short_option
|
20
|
+
"with_short_message('#{ options[:too_short] }')"
|
21
|
+
end
|
22
|
+
|
23
|
+
def too_long_option
|
24
|
+
"with_long_message('#{ options[:too_long] }')"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module AutoSpecs
|
2
|
+
module ActiveRecord
|
3
|
+
module Validations
|
4
|
+
module Helpers
|
5
|
+
module NumericalityMethods
|
6
|
+
[:less_than, :less_than_or_equal_to, :equal_to, :greater_than, :greater_than_or_equal_to].each do |option|
|
7
|
+
method_name = "#{ option }_option"
|
8
|
+
define_method method_name do
|
9
|
+
"is_#{ option }(#{ options[option] })"
|
10
|
+
end
|
11
|
+
private method_name
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
def only_integer_option
|
16
|
+
"only_integer"
|
17
|
+
end
|
18
|
+
|
19
|
+
def even_option
|
20
|
+
options[:even] ? "even" : "odd"
|
21
|
+
end
|
22
|
+
|
23
|
+
def odd_option
|
24
|
+
options[:odd] ? "odd" : "even"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module AutoSpecs
|
2
|
+
module ActiveRecord
|
3
|
+
module Validations
|
4
|
+
MAPPINGS = {
|
5
|
+
'PresenceValidator' => 'validate_presence_of',
|
6
|
+
'UniquenessValidator' => 'validate_uniqueness_of',
|
7
|
+
'NumericalityValidator' => 'validate_numericality_of',
|
8
|
+
'LengthValidator' => 'validate_length_of',
|
9
|
+
'ConfirmationValidator' => 'validate_confirmation_of',
|
10
|
+
'InclusionValidator' => 'validate_inclusion_of',
|
11
|
+
'ExclusionValidator' => 'validate_exclusion_of'
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'auto_specs/active_record/validations/mapping'
|
2
|
+
require 'auto_specs/active_record/validations/helpers/general_methods'
|
3
|
+
require 'auto_specs/active_record/validations/helpers/numericality_methods'
|
4
|
+
require 'auto_specs/active_record/validations/helpers/length_methods'
|
5
|
+
require 'auto_specs/active_record/validations/helpers/inclusion_methods'
|
6
|
+
|
7
|
+
module AutoSpecs
|
8
|
+
module ActiveRecord
|
9
|
+
module Validations
|
10
|
+
class SpecBuilder
|
11
|
+
include Helpers::GeneralMethods
|
12
|
+
include Helpers::NumericalityMethods
|
13
|
+
include Helpers::LengthMethods
|
14
|
+
include Helpers::InclusionMethods
|
15
|
+
|
16
|
+
attr_accessor :attributes, :validator_class, :options
|
17
|
+
|
18
|
+
def initialize(validator_object)
|
19
|
+
@validator_class = validator_object.class.to_s.demodulize
|
20
|
+
@attributes = validator_object.attributes
|
21
|
+
@options = validator_object.options
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
attributes.collect do |_attr_|
|
26
|
+
"it { should #{ shoulda_validation_mapping }(:#{ _attr_ })#{ append_options } }"
|
27
|
+
end.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def shoulda_validation_mapping
|
32
|
+
ActiveRecord::Validations::MAPPINGS[validator_class]
|
33
|
+
end
|
34
|
+
|
35
|
+
def append_options
|
36
|
+
options.keys.collect do |key|
|
37
|
+
send("#{ key }_option")
|
38
|
+
end.join(".").prepend('.')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'auto_specs/generators/base'
|
2
2
|
require 'auto_specs/active_record/associations/spec_builder'
|
3
|
+
require 'auto_specs/active_record/validations/spec_builder'
|
3
4
|
|
4
5
|
module AutoSpecs
|
5
6
|
module Generators
|
@@ -22,7 +23,7 @@ module AutoSpecs
|
|
22
23
|
def push_file
|
23
24
|
within_file_code do
|
24
25
|
generate_code_for_associations
|
25
|
-
|
26
|
+
generate_code_for_validations
|
26
27
|
end
|
27
28
|
write_file
|
28
29
|
end
|
@@ -53,8 +54,12 @@ describe #{ model_name } do)
|
|
53
54
|
def generate_code_for_validations
|
54
55
|
generate_code_block_for('Validations')
|
55
56
|
model_name.validators.each do |validator|
|
56
|
-
|
57
|
+
self.file_contents += %Q(
|
58
|
+
#{ AutoSpecs::ActiveRecord::Validations::SpecBuilder.new(validator).to_s })
|
57
59
|
end
|
60
|
+
self.file_contents += %Q(
|
61
|
+
end
|
62
|
+
)
|
58
63
|
end
|
59
64
|
|
60
65
|
def generate_code_block_for(entity)
|
data/lib/auto_specs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_specs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha
|
4
|
+
version: 0.0.1.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aditya Kapoor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
-
description: '
|
41
|
+
description: Don't Write Specs Yourself.
|
42
42
|
email:
|
43
43
|
- aditya.kapoor@vinsol.com
|
44
44
|
executables: []
|
@@ -55,6 +55,12 @@ files:
|
|
55
55
|
- lib/auto_specs/active_record/associations/mapping.rb
|
56
56
|
- lib/auto_specs/active_record/associations/spec_builder.rb
|
57
57
|
- lib/auto_specs/active_record/models/generator.rb
|
58
|
+
- lib/auto_specs/active_record/validations/helpers/general_methods.rb
|
59
|
+
- lib/auto_specs/active_record/validations/helpers/inclusion_methods.rb
|
60
|
+
- lib/auto_specs/active_record/validations/helpers/length_methods.rb
|
61
|
+
- lib/auto_specs/active_record/validations/helpers/numericality_methods.rb
|
62
|
+
- lib/auto_specs/active_record/validations/mapping.rb
|
63
|
+
- lib/auto_specs/active_record/validations/spec_builder.rb
|
58
64
|
- lib/auto_specs/generators/base.rb
|
59
65
|
- lib/auto_specs/generators/model.rb
|
60
66
|
- lib/auto_specs/tasks.rb
|