rapid-core 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/.rspec +2 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +53 -0
- data/Rakefile +61 -0
- data/cucumber.yml +3 -0
- data/doc/plan.txt +89 -0
- data/doc/scaffold/controller.rb +83 -0
- data/doc/scaffold/helper.rb +2 -0
- data/doc/scaffold/model.rb +5 -0
- data/doc/scaffold/rapid_scaffold.rb +5 -0
- data/doc/scaffold/views/_form.html.erb +25 -0
- data/doc/scaffold/views/edit.html.erb +6 -0
- data/doc/scaffold/views/index.html.erb +25 -0
- data/doc/scaffold/views/new.html.erb +5 -0
- data/doc/scaffold/views/show.html.erb +15 -0
- data/features/settings/boolean/default.feature +36 -0
- data/features/settings/double-nested/default.feature +50 -0
- data/features/settings/double-nested/if.feature +41 -0
- data/features/settings/double-nested/unless.feature +39 -0
- data/features/settings/double-nested/validates/exclusion_of.feature +30 -0
- data/features/settings/double-nested/validates/format_of.feature +30 -0
- data/features/settings/double-nested/validates/inclusion_of.feature +30 -0
- data/features/settings/double-nested/validates/length_of.feature +30 -0
- data/features/settings/double-nested/validates/presence_of.feature +37 -0
- data/features/settings/double-nested/validates/size_of.feature +30 -0
- data/features/settings/integer/default.feature +49 -0
- data/features/settings/nested/default.feature +50 -0
- data/features/settings/nested/if.feature +53 -0
- data/features/settings/nested/unless.feature +32 -0
- data/features/settings/nested/validates/exclusion_of.feature +30 -0
- data/features/settings/nested/validates/format_of.feature +30 -0
- data/features/settings/nested/validates/inclusion_of.feature +30 -0
- data/features/settings/nested/validates/length_of.feature +30 -0
- data/features/settings/nested/validates/presence_of.feature +37 -0
- data/features/settings/nested/validates/size_of.feature +30 -0
- data/features/settings/not_found.feature +33 -0
- data/features/settings/string/default.feature +36 -0
- data/features/settings/string/validates/exclusion_of.feature +30 -0
- data/features/settings/string/validates/format_of.feature +30 -0
- data/features/settings/string/validates/inclusion_of.feature +30 -0
- data/features/settings/string/validates/length_of.feature +30 -0
- data/features/settings/string/validates/presence_of.feature +37 -0
- data/features/settings/string/validates/size_of.feature +30 -0
- data/features/step_definitions/settings_steps.rb +92 -0
- data/features/step_definitions/skeleton_steps.rb +68 -0
- data/features/step_definitions/template_steps.rb +39 -0
- data/features/support/env.rb +6 -0
- data/features/templates/comment_if.feature +55 -0
- data/features/templates/comment_unless.feature +56 -0
- data/features/templates/for/for.feature +51 -0
- data/features/templates/if/else.feature +60 -0
- data/features/templates/if/elsif.feature +82 -0
- data/features/templates/if/if.feature +55 -0
- data/features/templates/namespaces/exist.feature +54 -0
- data/features/templates/static.feature +37 -0
- data/features/templates/variables.feature +61 -0
- data/lib/rapid/check.rb +162 -0
- data/lib/rapid/core.rb +37 -0
- data/lib/rapid/error.rb +84 -0
- data/lib/rapid/module.rb +35 -0
- data/lib/rapid/railtie.rb +18 -0
- data/lib/rapid/setting/base.rb +35 -0
- data/lib/rapid/setting/boolean_setting.rb +17 -0
- data/lib/rapid/setting/class_hash.rb +34 -0
- data/lib/rapid/setting/comments.rb +25 -0
- data/lib/rapid/setting/definer.rb +151 -0
- data/lib/rapid/setting/instance_hash.rb +132 -0
- data/lib/rapid/setting/instance_root.rb +107 -0
- data/lib/rapid/setting/integer_setting.rb +24 -0
- data/lib/rapid/setting/namespace/base.rb +113 -0
- data/lib/rapid/setting/namespace/instance.rb +84 -0
- data/lib/rapid/setting/nested_validations.rb +86 -0
- data/lib/rapid/setting/string_setting.rb +13 -0
- data/lib/rapid/settings.rb +129 -0
- data/lib/rapid/skeleton/base.rb +164 -0
- data/lib/rapid/skeleton/helpers/directory.rb +53 -0
- data/lib/rapid/skeleton/helpers/gem.rb +133 -0
- data/lib/rapid/skeleton/helpers/migration.rb +46 -0
- data/lib/rapid/skeleton/helpers/route.rb +115 -0
- data/lib/rapid/skeleton/helpers/script.rb +33 -0
- data/lib/rapid/skeleton/helpers/template.rb +73 -0
- data/lib/rapid/skeleton/helpers/view.rb +35 -0
- data/lib/rapid/spec/template.rb +104 -0
- data/lib/rapid/spec.rb +1 -0
- data/lib/rapid/tasks.rb +29 -0
- data/lib/rapid/template/base.rb +49 -0
- data/lib/rapid/template/node/base.rb +43 -0
- data/lib/rapid/template/node/comment_node.rb +42 -0
- data/lib/rapid/template/node/if_node.rb +109 -0
- data/lib/rapid/template/node/root.rb +51 -0
- data/lib/rapid/template/node/static.rb +29 -0
- data/lib/rapid/template/node/variable.rb +86 -0
- data/lib/rapid/template/parser.rb +167 -0
- data/lib/rapid/template/pulling/base.rb +91 -0
- data/lib/rapid/template/pulling/explicit.rb +92 -0
- data/lib/rapid/template/pulling/forgiving.rb +58 -0
- data/lib/rapid/version.rb +3 -0
- data/lib/rapid.rb +37 -0
- data/rapid-core.gemspec +26 -0
- data/spec/rapid/check_spec.rb +119 -0
- data/spec/rapid/error_spec.rb +14 -0
- data/spec/rapid/module_spec.rb +28 -0
- data/spec/rapid/setting/base_spec.rb +17 -0
- data/spec/rapid/setting/definer_spec.rb +318 -0
- data/spec/rapid/setting/instance_root_spec.rb +161 -0
- data/spec/rapid/setting/namespace/base_spec.rb +93 -0
- data/spec/rapid/setting/namespace/instance_spec.rb +12 -0
- data/spec/rapid/setting/nested_validations_spec.rb +72 -0
- data/spec/rapid/settings_spec.rb +51 -0
- data/spec/rapid/skeleton/base_spec.rb +224 -0
- data/spec/rapid/skeleton/helpers/directory_spec.rb +104 -0
- data/spec/rapid/skeleton/helpers/gem_spec.rb +180 -0
- data/spec/rapid/skeleton/helpers/migration_spec.rb +23 -0
- data/spec/rapid/skeleton/helpers/route_spec.rb +120 -0
- data/spec/rapid/skeleton/helpers/script_spec.rb +57 -0
- data/spec/rapid/skeleton/helpers/template_spec.rb +142 -0
- data/spec/rapid/skeleton/helpers/view_spec.rb +54 -0
- data/spec/rapid/spec/template_spec.rb +168 -0
- data/spec/rapid/template/base_spec.rb +290 -0
- data/spec/rapid/template/node/base_spec.rb +9 -0
- data/spec/rapid/template/node/comment_node_spec.rb +46 -0
- data/spec/rapid/template/node/if_node_spec.rb +28 -0
- data/spec/rapid/template/node/root_spec.rb +9 -0
- data/spec/rapid/template/node/static_spec.rb +17 -0
- data/spec/rapid/template/node/variable_spec.rb +87 -0
- data/spec/rapid/template/parser_spec.rb +187 -0
- data/spec/rapid/template/pulling/base_spec.rb +81 -0
- data/spec/rapid/template/pulling/explicit_spec.rb +33 -0
- data/spec/rapid/template/pulling/forgiving_spec.rb +132 -0
- data/spec/spec_helper.rb +10 -0
- metadata +325 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
Feature: string with validates_presence_of
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given settings "my_settings.rb":
|
5
|
+
"""
|
6
|
+
class MySettings
|
7
|
+
include Rapid::Settings
|
8
|
+
|
9
|
+
setting.string :name
|
10
|
+
|
11
|
+
validates_presence_of :name
|
12
|
+
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: Non-blank value
|
17
|
+
When I load:
|
18
|
+
"""
|
19
|
+
name: Dan
|
20
|
+
"""
|
21
|
+
Then I should be good
|
22
|
+
And vice versa
|
23
|
+
|
24
|
+
Scenario: nil value
|
25
|
+
When I load:
|
26
|
+
"""
|
27
|
+
"""
|
28
|
+
Then "name" should have a "can't be blank" error
|
29
|
+
And vice versa
|
30
|
+
|
31
|
+
Scenario: blank value
|
32
|
+
When I load:
|
33
|
+
"""
|
34
|
+
name:
|
35
|
+
"""
|
36
|
+
Then "name" should have a "can't be blank" error
|
37
|
+
And vice versa
|
@@ -0,0 +1,30 @@
|
|
1
|
+
Feature: string validates_size_of
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given settings "my_settings.rb":
|
5
|
+
"""
|
6
|
+
class MySettings
|
7
|
+
include Rapid::Settings
|
8
|
+
|
9
|
+
setting.string :name
|
10
|
+
|
11
|
+
validates_size_of :name, :minimum => 3
|
12
|
+
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: Valid value
|
17
|
+
When I load:
|
18
|
+
"""
|
19
|
+
name: Dan
|
20
|
+
"""
|
21
|
+
Then I should be good
|
22
|
+
And vice versa
|
23
|
+
|
24
|
+
Scenario: Invalid value
|
25
|
+
When I load:
|
26
|
+
"""
|
27
|
+
name: Me
|
28
|
+
"""
|
29
|
+
Then "name" should have a "is too short (minimum is 3 characters)" error
|
30
|
+
And vice versa
|
@@ -0,0 +1,92 @@
|
|
1
|
+
After do
|
2
|
+
@ruby_classnames.each do |ruby_classname|
|
3
|
+
Object.send(:remove_const, ruby_classname.to_sym) rescue nil
|
4
|
+
end
|
5
|
+
@ruby_classnames = nil
|
6
|
+
|
7
|
+
@settingss = nil
|
8
|
+
|
9
|
+
@current_settings_class = nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_settings_class filename
|
13
|
+
if @settingss.nil?
|
14
|
+
raise "Could not find settings #{filename.inspect}. No settingss defined"
|
15
|
+
end
|
16
|
+
|
17
|
+
settings = @settingss[filename]
|
18
|
+
|
19
|
+
if settings.nil?
|
20
|
+
raise "Could not find settings #{filename.inspect}. Skeletons available: #{@settingss.keys.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
settings
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_settings_class ruby_filename, ruby_code
|
27
|
+
result = eval ruby_code
|
28
|
+
|
29
|
+
ruby_classname = File.basename(ruby_filename, ".*").camelize
|
30
|
+
@ruby_class = ruby_classname.constantize
|
31
|
+
|
32
|
+
@ruby_classnames ||= []
|
33
|
+
@ruby_classnames.push ruby_classname
|
34
|
+
|
35
|
+
@settingss ||= {}
|
36
|
+
@settingss[ruby_filename] = @ruby_class
|
37
|
+
@current_settings_class = @ruby_class
|
38
|
+
end
|
39
|
+
|
40
|
+
Given /^settings "([^\"]*)":$/ do |ruby_filename, ruby_code|
|
41
|
+
create_settings_class ruby_filename, ruby_code
|
42
|
+
end
|
43
|
+
|
44
|
+
When /^I load:$/ do |yaml_content|
|
45
|
+
@current_yaml = yaml_content
|
46
|
+
@current_settings = @current_settings_class.new
|
47
|
+
@current_settings.settings.load_yaml yaml_content
|
48
|
+
end
|
49
|
+
|
50
|
+
Then /^I should be good$/ do
|
51
|
+
unless @current_settings.valid?
|
52
|
+
raise "You aren't good: #{@current_settings.errors.full_messages.join(', ')}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Then /^"([^\"]*)" should have a "([^\"]*)" error$/ do |attribute_name, error_message|
|
57
|
+
if @current_settings.nil?
|
58
|
+
raise "You haven't loaded a settings"
|
59
|
+
end
|
60
|
+
|
61
|
+
@current_settings.valid?
|
62
|
+
errors = @current_settings.errors[attribute_name]
|
63
|
+
|
64
|
+
if errors.blank?
|
65
|
+
raise "#{attribute_name} does not have any errors"
|
66
|
+
end
|
67
|
+
|
68
|
+
errors.should include(error_message)
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
Then /^vice versa$/ do
|
73
|
+
if @current_yaml && @current_settings
|
74
|
+
yaml = @current_settings.settings.to_yaml
|
75
|
+
yaml.should == @current_yaml
|
76
|
+
|
77
|
+
elsif @current_template
|
78
|
+
original_settings = @current_settings
|
79
|
+
|
80
|
+
new_hash = @current_template.pull @current_template_content
|
81
|
+
new_settings = @current_settings.class.new
|
82
|
+
|
83
|
+
new_hash.each do |key, value|
|
84
|
+
new_settings.settings[key] = value
|
85
|
+
end
|
86
|
+
|
87
|
+
new_settings.settings.to_dot_hash.should == original_settings.settings.to_dot_hash
|
88
|
+
|
89
|
+
else
|
90
|
+
raise "Not sure what I need to reverse verify"
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
Given /^a skeleton with settings "([^\"]*)":$/ do |settings_filename, settings_content|
|
2
|
+
create_settings_class settings_filename, settings_content
|
3
|
+
|
4
|
+
@current_yaml = settings_content
|
5
|
+
@current_settings = @current_settings_class.new
|
6
|
+
@current_skeleton = Rapid::Skeleton::Base.new @current_settings
|
7
|
+
end
|
8
|
+
|
9
|
+
# After do
|
10
|
+
# @ruby_classnames.each do |ruby_classname|
|
11
|
+
# Object.send(:remove_const, ruby_classname.to_sym) rescue nil
|
12
|
+
# end
|
13
|
+
# @ruby_classnames = nil
|
14
|
+
#
|
15
|
+
# @skeletons = nil
|
16
|
+
#
|
17
|
+
# @current_skeleton_class = nil
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# def find_skeleton_class filename
|
21
|
+
# if @skeletons.nil?
|
22
|
+
# raise "Could not find skeleton #{filename.inspect}. No skeletons defined"
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
# skeleton = @skeletons[filename]
|
26
|
+
#
|
27
|
+
# if skeleton.nil?
|
28
|
+
# raise "Could not find skeleton #{filename.inspect}. Skeletons available: #{@skeletons.keys.inspect}"
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# skeleton
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# Given /^a skeleton "([^\"]*)":$/ do |ruby_filename, ruby_code|
|
35
|
+
# result = eval ruby_code
|
36
|
+
#
|
37
|
+
# ruby_classname = File.basename(ruby_filename, ".*").camelize
|
38
|
+
# @ruby_class = ruby_classname.constantize
|
39
|
+
#
|
40
|
+
# @ruby_classnames ||= []
|
41
|
+
# @ruby_classnames.push ruby_classname
|
42
|
+
#
|
43
|
+
# @skeletons ||= {}
|
44
|
+
# @skeletons[ruby_filename] = @ruby_class
|
45
|
+
# @current_skeleton_class = @ruby_class
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# Then /^vice versa$/ do
|
49
|
+
# if @current_yaml && @current_skeleton
|
50
|
+
# yaml = @current_skeleton.settings.to_yaml
|
51
|
+
# yaml.should == @current_yaml
|
52
|
+
#
|
53
|
+
# elsif @current_template
|
54
|
+
# original_skeleton = @current_skeleton
|
55
|
+
#
|
56
|
+
# new_hash = @current_template.pull @current_template_content
|
57
|
+
# new_skeleton = @current_skeleton.class.new
|
58
|
+
#
|
59
|
+
# new_hash.each do |key, value|
|
60
|
+
# new_skeleton.settings[key] = value
|
61
|
+
# end
|
62
|
+
#
|
63
|
+
# new_skeleton.settings.to_dot_hash.should == original_skeleton.settings.to_dot_hash
|
64
|
+
#
|
65
|
+
# else
|
66
|
+
# raise "Not sure what I need to reverse verify"
|
67
|
+
# end
|
68
|
+
# end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
After do
|
2
|
+
@current_template = nil
|
3
|
+
end
|
4
|
+
|
5
|
+
def find_template filename
|
6
|
+
if @templates.nil?
|
7
|
+
raise "Could not find template #{filename.inspect}. No templates defined"
|
8
|
+
end
|
9
|
+
|
10
|
+
template = @templates[filename]
|
11
|
+
|
12
|
+
if template.nil?
|
13
|
+
raise "Could not find template #{filename.inspect}. Templates available: #{@templates.keys.inspect}"
|
14
|
+
end
|
15
|
+
|
16
|
+
template
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
Given /^a template "([^\"]*)":$/ do |template_filename, template_content|
|
21
|
+
@current_template = Rapid::Template::Base.new template_content, :filename => template_filename
|
22
|
+
|
23
|
+
@templates ||= {}
|
24
|
+
@templates[template_filename] = @current_template
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^I push the skeleton through "([^\"]*)" with:$/ do |template_filename, settings_content|
|
28
|
+
@current_template = find_template template_filename
|
29
|
+
|
30
|
+
@current_yaml = settings_content
|
31
|
+
@current_skeleton.load_yaml settings_content
|
32
|
+
|
33
|
+
@current_template_content = @current_template.push @current_skeleton
|
34
|
+
end
|
35
|
+
|
36
|
+
Then /^I should get:$/ do |content|
|
37
|
+
@current_template_content.should == content
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Feature: template with a comment_if function call
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a skeleton with settings "my_settings.rb":
|
5
|
+
"""
|
6
|
+
class MySettings
|
7
|
+
include Rapid::Settings
|
8
|
+
|
9
|
+
setting.boolean :foo
|
10
|
+
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
And a template "static.erb":
|
14
|
+
"""
|
15
|
+
class Foo < ActiveRecord::Base
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
<%= comment_if foo %>"foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
"""
|
23
|
+
|
24
|
+
Scenario: comment
|
25
|
+
When I push the skeleton through "static.erb" with:
|
26
|
+
"""
|
27
|
+
foo: true
|
28
|
+
"""
|
29
|
+
Then I should get:
|
30
|
+
"""
|
31
|
+
class Foo < ActiveRecord::Base
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
# "foo"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
"""
|
39
|
+
# And vice versa
|
40
|
+
|
41
|
+
Scenario: no comment
|
42
|
+
When I push the skeleton through "static.erb" with:
|
43
|
+
"""
|
44
|
+
"""
|
45
|
+
Then I should get:
|
46
|
+
"""
|
47
|
+
class Foo < ActiveRecord::Base
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
"foo"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
"""
|
55
|
+
# And vice versa
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Feature: template with a comment_unless function call
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a skeleton with settings "my_settings.rb":
|
5
|
+
"""
|
6
|
+
class MySettings
|
7
|
+
include Rapid::Settings
|
8
|
+
|
9
|
+
setting.boolean :foo
|
10
|
+
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
And a template "static.erb":
|
14
|
+
"""
|
15
|
+
class Foo < ActiveRecord::Base
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
<%= comment_unless foo %>"foo"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
"""
|
23
|
+
|
24
|
+
Scenario: comment
|
25
|
+
When I push the skeleton through "static.erb" with:
|
26
|
+
"""
|
27
|
+
foo: true
|
28
|
+
"""
|
29
|
+
Then I should get:
|
30
|
+
"""
|
31
|
+
class Foo < ActiveRecord::Base
|
32
|
+
|
33
|
+
def inspect
|
34
|
+
"foo"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
"""
|
39
|
+
# And vice versa
|
40
|
+
|
41
|
+
Scenario: no comment
|
42
|
+
When I push the skeleton through "static.erb" with:
|
43
|
+
"""
|
44
|
+
"""
|
45
|
+
Then I should get:
|
46
|
+
"""
|
47
|
+
class Foo < ActiveRecord::Base
|
48
|
+
|
49
|
+
def inspect
|
50
|
+
# "foo"
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
"""
|
55
|
+
# And vice versa
|
56
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# @wip
|
2
|
+
# Feature: push and pull a template with a for loop
|
3
|
+
#
|
4
|
+
# Background:
|
5
|
+
# Given a skeleton with settings "my_settings.rb":
|
6
|
+
# """
|
7
|
+
# class MySettings
|
8
|
+
# include Rapid::Settings
|
9
|
+
#
|
10
|
+
# def items
|
11
|
+
# %w(far bar baz)
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# end
|
15
|
+
# """
|
16
|
+
# And a template "static.erb":
|
17
|
+
# """
|
18
|
+
# class Foo < ActiveRecord::Base
|
19
|
+
#
|
20
|
+
# <% for item in items -%>
|
21
|
+
# def <%= item %>
|
22
|
+
# "<%= item %>"
|
23
|
+
# end
|
24
|
+
# <% end -%>
|
25
|
+
#
|
26
|
+
# end
|
27
|
+
# """
|
28
|
+
#
|
29
|
+
# Scenario: Push and Pull Template
|
30
|
+
# When I push the skeleton through "static.erb" with:
|
31
|
+
# """
|
32
|
+
# """
|
33
|
+
# Then I should get:
|
34
|
+
# """
|
35
|
+
# class Foo < ActiveRecord::Base
|
36
|
+
#
|
37
|
+
# def foo
|
38
|
+
# "foo"
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# def bar
|
42
|
+
# "bar"
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# def baz
|
46
|
+
# "baz"
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# end
|
50
|
+
# """
|
51
|
+
# And vice versa
|
@@ -0,0 +1,60 @@
|
|
1
|
+
Feature: template with an if-else statement
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a template "if.erb":
|
5
|
+
"""
|
6
|
+
class Foo < ActiveRecord::Base
|
7
|
+
|
8
|
+
def inspect
|
9
|
+
<% if has_inspect %>
|
10
|
+
"foo"
|
11
|
+
<% else %>
|
12
|
+
raise "Not implemented"
|
13
|
+
<% end %>
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
"""
|
18
|
+
And a skeleton with settings "my_settings.rb":
|
19
|
+
"""
|
20
|
+
class MySettings
|
21
|
+
include Rapid::Settings
|
22
|
+
|
23
|
+
setting.boolean :has_inspect
|
24
|
+
|
25
|
+
end
|
26
|
+
"""
|
27
|
+
|
28
|
+
Scenario: true
|
29
|
+
When I push the skeleton through "if.erb" with:
|
30
|
+
"""
|
31
|
+
has_inspect: true
|
32
|
+
"""
|
33
|
+
Then I should get:
|
34
|
+
"""
|
35
|
+
class Foo < ActiveRecord::Base
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
"foo"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
"""
|
43
|
+
And vice versa
|
44
|
+
|
45
|
+
Scenario: false
|
46
|
+
When I push the skeleton through "if.erb" with:
|
47
|
+
"""
|
48
|
+
has_inspect: false
|
49
|
+
"""
|
50
|
+
Then I should get:
|
51
|
+
"""
|
52
|
+
class Foo < ActiveRecord::Base
|
53
|
+
|
54
|
+
def inspect
|
55
|
+
raise "Not implemented"
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
"""
|
60
|
+
And vice versa
|
@@ -0,0 +1,82 @@
|
|
1
|
+
Feature: template with an if-elsif-else statement
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a template "if.erb":
|
5
|
+
"""
|
6
|
+
class Foo < ActiveRecord::Base
|
7
|
+
|
8
|
+
def inspect
|
9
|
+
<% if has_inspect %>
|
10
|
+
"foo"
|
11
|
+
<% elsif raise %>
|
12
|
+
raise "Not implemented"
|
13
|
+
<% else %>
|
14
|
+
|
15
|
+
<% end %>
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
"""
|
20
|
+
And a skeleton with settings "my_settings.rb":
|
21
|
+
"""
|
22
|
+
class MySettings
|
23
|
+
include Rapid::Settings
|
24
|
+
|
25
|
+
setting.boolean :has_inspect
|
26
|
+
setting.boolean :raise
|
27
|
+
|
28
|
+
end
|
29
|
+
"""
|
30
|
+
|
31
|
+
Scenario: if
|
32
|
+
When I push the skeleton through "if.erb" with:
|
33
|
+
"""
|
34
|
+
has_inspect: true
|
35
|
+
"""
|
36
|
+
Then I should get:
|
37
|
+
"""
|
38
|
+
class Foo < ActiveRecord::Base
|
39
|
+
|
40
|
+
def inspect
|
41
|
+
"foo"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
"""
|
46
|
+
And vice versa
|
47
|
+
|
48
|
+
Scenario: elsif
|
49
|
+
When I push the skeleton through "if.erb" with:
|
50
|
+
"""
|
51
|
+
raise: true
|
52
|
+
has_inspect: false
|
53
|
+
"""
|
54
|
+
Then I should get:
|
55
|
+
"""
|
56
|
+
class Foo < ActiveRecord::Base
|
57
|
+
|
58
|
+
def inspect
|
59
|
+
raise "Not implemented"
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
"""
|
64
|
+
And vice versa
|
65
|
+
|
66
|
+
Scenario: else
|
67
|
+
When I push the skeleton through "if.erb" with:
|
68
|
+
"""
|
69
|
+
raise: false
|
70
|
+
has_inspect: false
|
71
|
+
"""
|
72
|
+
Then I should get:
|
73
|
+
"""
|
74
|
+
class Foo < ActiveRecord::Base
|
75
|
+
|
76
|
+
def inspect
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
"""
|
82
|
+
And vice versa
|
@@ -0,0 +1,55 @@
|
|
1
|
+
Feature: template with an if statement
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a template "if.erb":
|
5
|
+
"""
|
6
|
+
class Foo < ActiveRecord::Base
|
7
|
+
|
8
|
+
<% if has_inspect? %>
|
9
|
+
def inspect
|
10
|
+
"foo"
|
11
|
+
end
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
And a skeleton with settings "my_settings.rb":
|
17
|
+
"""
|
18
|
+
class MySettings
|
19
|
+
include Rapid::Settings
|
20
|
+
|
21
|
+
setting.boolean :has_inspect
|
22
|
+
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
|
26
|
+
Scenario: true
|
27
|
+
When I push the skeleton through "if.erb" with:
|
28
|
+
"""
|
29
|
+
has_inspect: true
|
30
|
+
"""
|
31
|
+
Then I should get:
|
32
|
+
"""
|
33
|
+
class Foo < ActiveRecord::Base
|
34
|
+
|
35
|
+
def inspect
|
36
|
+
"foo"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
And vice versa
|
42
|
+
|
43
|
+
Scenario: false
|
44
|
+
When I push the skeleton through "if.erb" with:
|
45
|
+
"""
|
46
|
+
has_inspect: false
|
47
|
+
"""
|
48
|
+
Then I should get:
|
49
|
+
"""
|
50
|
+
class Foo < ActiveRecord::Base
|
51
|
+
|
52
|
+
|
53
|
+
end
|
54
|
+
"""
|
55
|
+
And vice versa
|
@@ -0,0 +1,54 @@
|
|
1
|
+
Feature: does a namespace exist
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given a skeleton with settings "my_settings.rb":
|
5
|
+
"""
|
6
|
+
class MySettings
|
7
|
+
include Rapid::Settings
|
8
|
+
|
9
|
+
setting.string 'app.author.name'
|
10
|
+
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
And a template "variables.erb":
|
14
|
+
"""
|
15
|
+
class App < ActiveRecord::Base
|
16
|
+
|
17
|
+
<% if app.author? %>
|
18
|
+
def author_name
|
19
|
+
"<%= app.author.name %>"
|
20
|
+
end
|
21
|
+
<% end %>
|
22
|
+
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
|
26
|
+
Scenario: does not exist
|
27
|
+
When I push the skeleton through "variables.erb" with:
|
28
|
+
"""
|
29
|
+
"""
|
30
|
+
Then I should get:
|
31
|
+
"""
|
32
|
+
class App < ActiveRecord::Base
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
"""
|
37
|
+
And vice versa
|
38
|
+
|
39
|
+
Scenario: exists
|
40
|
+
When I push the skeleton through "variables.erb" with:
|
41
|
+
"""
|
42
|
+
app.author.name: Dan
|
43
|
+
"""
|
44
|
+
Then I should get:
|
45
|
+
"""
|
46
|
+
class App < ActiveRecord::Base
|
47
|
+
|
48
|
+
def author_name
|
49
|
+
"Dan"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
"""
|
54
|
+
And vice versa
|