self_systeem 0.0.2 → 0.0.3
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 +105 -5
- data/lib/generators/self_systeem/templates/systeem_test.rb +11 -3
- data/lib/self_systeem.rb +3 -1
- data/lib/self_systeem/affirmation_builder.rb +67 -22
- data/lib/self_systeem/instance_variables_builder.rb +62 -0
- data/lib/self_systeem/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9de54012651cf7ecfb8be4425844e0d53df4e308
|
4
|
+
data.tar.gz: 27d9e804227cb2c399a5c7b9ced9f92d65c264c7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46267c6ddd61cec31f64abe1535c32b3d1e597b3418f23866c6591cc9f8e01def74a889f83cabd775c46ebc214d53f5f35e1bc5856c47f89527ebe07078d2f52
|
7
|
+
data.tar.gz: 23451262d6da7d07ded730df9eaabe0c85b706619c1b93431c6cc82abaccf13dfbc20d05289c0cebfa3afba4c8fb828d4e0069fed911c1c059b3e222b86013a7
|
data/README.md
CHANGED
@@ -1,12 +1,69 @@
|
|
1
|
-
|
1
|
+
self_systeem
|
2
|
+
============
|
3
|
+
| Project | Gem Release |
|
4
|
+
|------------------------ | ----------------- |
|
5
|
+
| Gem name | self_systeem |
|
6
|
+
| License | [MIT](LICENSE.txt) |
|
7
|
+
| Version | [](http://badge.fury.io/rb/self_systeem) |
|
8
|
+
| Continuous Integration | [](https://travis-ci.org/mfpiccolo/self_systeem)
|
9
|
+
| Test Coverage | [](https://coveralls.io/r/mfpiccolo/self_systeem?branch=coveralls)
|
10
|
+
| Grade | [](https://codeclimate.com/github/mfpiccolo/self_systeem)
|
11
|
+
| Dependencies | [](https://gemnasium.com/mfpiccolo/self_systeem)
|
12
|
+
| Homepage | [http://mfpiccolo.github.io/self_systeem][homepage] |
|
13
|
+
| Documentation | [http://rdoc.info/github/mfpiccolo/self_systeem/frames][documentation] |
|
14
|
+
| Issues | [https://github.com/mfpiccolo/self_systeem/issues][issues] |
|
2
15
|
|
3
|
-
|
16
|
+
## Description
|
17
|
+
|
18
|
+
###Definition: self-systeem
|
19
|
+
noun
|
20
|
+
|
21
|
+
1. a realistic respect for or favorable impression of one's system
|
22
|
+
2. confidence in one's system worth or abilities
|
23
|
+
3. system-respect
|
24
|
+
|
25
|
+
Do you have low self-systeem? Don't worry. This gem is here to help.
|
26
|
+
|
27
|
+
self_systeem allows you to record a users interaction with your rails app in a
|
28
|
+
development enviornment and automatically creates system tests based on the
|
29
|
+
recordings.
|
30
|
+
|
31
|
+
It is simple. Walk through the app from sart to finish. Cover as much as you
|
32
|
+
feel comfortable. That't it. You just built a system test. Congrats!
|
33
|
+
|
34
|
+
## Features
|
35
|
+
|
36
|
+
After setting up self_systeem (see configuration below) use the generator to create
|
37
|
+
the system test directory.
|
38
|
+
|
39
|
+
`rails g self_systeem:test`
|
40
|
+
|
41
|
+
Then run `SELF_SYSTEEM=true rails s`
|
42
|
+
|
43
|
+
Now open a new browser preferably in incognito mode so you have fresh session.
|
44
|
+
Walk through your app like a normal user would. While you are doing this positive
|
45
|
+
affirmations are being built in "test/system/support/systeem_booster.yml"
|
46
|
+
|
47
|
+
Now just run the test file with `ruby -Itest test/system/systeem_test.rb` and watch
|
48
|
+
you tests turn green. What does this really get you? Well for one the session and
|
49
|
+
database is persisted while runnin all these tests. That means that when you are running
|
50
|
+
your tests it is essentially a recreation of all of those users actions in sequence.
|
51
|
+
|
52
|
+
Possitive affirmations:
|
53
|
+
* "Today, my system choose to see love instead of fear"
|
54
|
+
* "My system possess the qualities needed to be extremely successful"
|
55
|
+
|
56
|
+
Feeling better?
|
57
|
+
|
58
|
+
Well if those didn't work you can always check out the affirmations that you have built in systeem_booster.yml. That should do the trick.
|
4
59
|
|
5
60
|
## Installation
|
6
61
|
|
7
62
|
Add this line to your application's Gemfile:
|
8
63
|
|
9
|
-
|
64
|
+
```ruby
|
65
|
+
gem "self_systeem"
|
66
|
+
```
|
10
67
|
|
11
68
|
And then execute:
|
12
69
|
|
@@ -16,9 +73,44 @@ Or install it yourself as:
|
|
16
73
|
|
17
74
|
$ gem install self_systeem
|
18
75
|
|
19
|
-
##
|
76
|
+
## Configuration
|
20
77
|
|
21
|
-
|
78
|
+
To use the generator run:
|
79
|
+
|
80
|
+
$ rails g self_systeem:test
|
81
|
+
|
82
|
+
This will set up a system folder under test with a test file and some support files.
|
83
|
+
|
84
|
+
Add this line to development.rb
|
85
|
+
|
86
|
+
`config.middleware.use "SelfSysteem::AffirmationBuilder" if ENV["SELF_SYSTEEM"].present?`
|
87
|
+
|
88
|
+
Temporarily change you database.yml so the development database uses the test database.
|
89
|
+
This step is only while you build systeem_booster.yml file. Chage it back when you are done.
|
90
|
+
|
91
|
+
i.e.
|
92
|
+
```ruby
|
93
|
+
development: &dev
|
94
|
+
adapter: postgresql
|
95
|
+
encoding: unicode
|
96
|
+
database: app_test # Change this back after creating the
|
97
|
+
pool: 5
|
98
|
+
username: <%= ENV["USER"] %>
|
99
|
+
password:
|
100
|
+
allow_concurrency: true
|
101
|
+
min_messages: warning
|
102
|
+
```
|
103
|
+
|
104
|
+
## Donating
|
105
|
+
Support this project and [others by mfpiccolo][gittip-mfpiccolo] via [gittip][gittip-mfpiccolo].
|
106
|
+
|
107
|
+
[gittip-mfpiccolo]: https://www.gittip.com/mfpiccolo/
|
108
|
+
|
109
|
+
## Copyright
|
110
|
+
|
111
|
+
Copyright (c) 2013 Mike Piccolo
|
112
|
+
|
113
|
+
See [LICENSE.txt](LICENSE.txt) for details.
|
22
114
|
|
23
115
|
## Contributing
|
24
116
|
|
@@ -27,3 +119,11 @@ TODO: Write usage instructions here
|
|
27
119
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
120
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
121
|
5. Create new Pull Request
|
122
|
+
|
123
|
+
[](http://githalytics.com/mfpiccolo/self_systeem)
|
124
|
+
|
125
|
+
[license]: https://github.com/mfpiccolo/self_systeem/MIT-LICENSE
|
126
|
+
[homepage]: http://mfpiccolo.github.io/self_systeem
|
127
|
+
[documentation]: http://rdoc.info/github/mfpiccolo/self_systeem/frames
|
128
|
+
[issues]: https://github.com/mfpiccolo/self_systeem/issues
|
129
|
+
|
@@ -1,24 +1,32 @@
|
|
1
1
|
require "./test/system/support/systeem_config.rb"
|
2
2
|
|
3
3
|
describe "start_db_cleaner" do
|
4
|
-
|
4
|
+
it { DatabaseCleaner.start }
|
5
5
|
end
|
6
6
|
|
7
7
|
SysteemConfig::Affirmations.each do |a|
|
8
8
|
describe a[:controller_class_name].constantize do
|
9
9
|
before do
|
10
|
+
# Only needed if devise
|
10
11
|
@request.env["devise.mapping"] = Devise.mappings[:user]
|
11
12
|
send(a[:request_method].downcase.to_sym, a[:action], a[:request_parameters], SysteemConfig::Session)
|
12
13
|
SysteemConfig::Session.merge! session
|
13
14
|
end
|
14
15
|
|
15
16
|
it {
|
16
|
-
|
17
|
+
controller_instance = response.request.env["action_controller.instance"]
|
18
|
+
builder = SelfSysteem::InstanceVariablesBuilder.call(controller_instance)
|
19
|
+
relevant_instance_varaibles = builder.relevant_instance_varaibles
|
20
|
+
instance_variable_objects = builder.instance_variable_objects
|
17
21
|
|
22
|
+
assert_response a[:status]
|
23
|
+
assert_equal(a[:relevant_instance_varaibles], relevant_instance_varaibles.to_s)
|
24
|
+
assert_equal(a[:instance_variable_objects], instance_variable_objects)
|
25
|
+
assert_equal(a[:templates], @_templates)
|
18
26
|
}
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
22
30
|
describe "db_cleaner_clean" do
|
23
|
-
|
31
|
+
it { DatabaseCleaner.clean }
|
24
32
|
end
|
data/lib/self_systeem.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require "self_systeem/version"
|
2
2
|
require "self_systeem/affirmation_builder"
|
3
|
+
require "self_systeem/instance_variables_builder"
|
3
4
|
|
4
|
-
module
|
5
|
+
module SelfSysteem
|
5
6
|
def self.included(base)
|
6
7
|
base.send(:include, SelfSysteem::AffirmationBuilder)
|
8
|
+
base.send(:include, SelfSysteem::InstanceVariablesBuilder)
|
7
9
|
super
|
8
10
|
end
|
9
11
|
end
|
@@ -6,9 +6,11 @@ module SelfSysteem
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def call(env)
|
9
|
+
|
9
10
|
if env["REQUEST_PATH"].match(/\/assets/)
|
10
11
|
status, headers, response = @app.call(env)
|
11
12
|
else
|
13
|
+
setup_subscriptions
|
12
14
|
status, headers, response = @app.call(env)
|
13
15
|
request_path = env["REQUEST_PATH"]
|
14
16
|
request_method = env["REQUEST_METHOD"]
|
@@ -17,26 +19,11 @@ module SelfSysteem
|
|
17
19
|
request_parameters.merge!(env["rack.request.form_hash"]) if env["rack.request.form_hash"].present?
|
18
20
|
request_parameters.merge!(env["action_controller.instance"].params.try(:to_hash)) if env["action_controller.instance"].params.present?
|
19
21
|
|
20
|
-
controller_instance = env["action_controller.instance"]
|
21
|
-
controller_class_name = controller_instance.try(:class).try(:name)
|
22
|
-
action = controller_instance.action_name
|
23
|
-
|
24
|
-
|
25
|
-
.instance_variable_names.reject {|v| v[/@_/] || v == "@marked_for_same_origin_verification"}
|
26
|
-
instance_variable_objects = {}
|
27
|
-
relevant_instance_varaibles.each do |v|
|
28
|
-
iv_val = controller_instance.instance_variable_get(v)
|
29
|
-
if iv_val.class.name.match(/ActiveRecord::AssociationRelation|ActiveRecord::Associations::CollectionProxy/)
|
30
|
-
instance_variable_objects.merge!(v.to_s => { })
|
31
|
-
iv_val.each do |o|
|
32
|
-
instance_variable_objects[v.to_s].merge!({ o.to_s => o.attributes })
|
33
|
-
end
|
34
|
-
elsif iv_val.is_a?(ActiveRecord::Base)
|
35
|
-
instance_variable_objects.merge!({ v.to_s => iv_val.attributes })
|
36
|
-
else
|
37
|
-
instance_variable_objects.merge!({ v.to_s => iv_val.to_s })
|
38
|
-
end
|
39
|
-
end
|
22
|
+
@controller_instance = env["action_controller.instance"]
|
23
|
+
controller_class_name = @controller_instance.try(:class).try(:name)
|
24
|
+
action = @controller_instance.action_name
|
25
|
+
|
26
|
+
setup_instance_varaibles
|
40
27
|
|
41
28
|
booster = {request_method: request_method,
|
42
29
|
request_path: request_path,
|
@@ -44,8 +31,12 @@ module SelfSysteem
|
|
44
31
|
request_parameters: request_parameters,
|
45
32
|
controller_class_name: controller_class_name,
|
46
33
|
status: status,
|
47
|
-
|
48
|
-
|
34
|
+
partials: @_partials,
|
35
|
+
layouts: @_layouts,
|
36
|
+
templates: @_templates,
|
37
|
+
files: @_files,
|
38
|
+
relevant_instance_varaibles: @relevant_instance_varaibles.to_s,
|
39
|
+
instance_variable_objects: @instance_variable_objects
|
49
40
|
}
|
50
41
|
|
51
42
|
unless File.exist?(Rails.root.to_s + "/test/system/support/systeem_booster.yml")
|
@@ -59,9 +50,63 @@ module SelfSysteem
|
|
59
50
|
File.open(Rails.root.to_s + "/test/system/support/systeem_booster.yml", 'w') do |file|
|
60
51
|
file.write(boosters.to_yaml)
|
61
52
|
end
|
53
|
+
|
54
|
+
teardown_subscriptions
|
62
55
|
end
|
63
56
|
|
64
57
|
[status, headers, [response.try(:body)].flatten]
|
65
58
|
end
|
59
|
+
|
60
|
+
def setup_instance_varaibles
|
61
|
+
builder = SelfSysteem::InstanceVariablesBuilder.call(@controller_instance)
|
62
|
+
@relevant_instance_varaibles = builder.relevant_instance_varaibles
|
63
|
+
@instance_variable_objects = builder.instance_variable_objects
|
64
|
+
end
|
65
|
+
|
66
|
+
def setup_subscriptions
|
67
|
+
@_partials = Hash.new(0)
|
68
|
+
@_templates = Hash.new(0)
|
69
|
+
@_layouts = Hash.new(0)
|
70
|
+
@_files = Hash.new(0)
|
71
|
+
|
72
|
+
ActiveSupport::Notifications.subscribe("render_template.action_view") do |_name, _start, _finish, _id, payload|
|
73
|
+
path = payload[:layout]
|
74
|
+
if path
|
75
|
+
@_layouts[path] += 1
|
76
|
+
if path =~ /^layouts\/(.*)/
|
77
|
+
@_layouts[$1] += 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
|
83
|
+
path = payload[:virtual_path]
|
84
|
+
next unless path
|
85
|
+
partial = path =~ /^.*\/_[^\/]*$/
|
86
|
+
|
87
|
+
if partial
|
88
|
+
@_partials[path] += 1
|
89
|
+
@_partials[path.split("/").last] += 1
|
90
|
+
end
|
91
|
+
|
92
|
+
@_templates[path] += 1
|
93
|
+
end
|
94
|
+
|
95
|
+
ActiveSupport::Notifications.subscribe("!render_template.action_view") do |_name, _start, _finish, _id, payload|
|
96
|
+
next if payload[:virtual_path] # files don't have virtual path
|
97
|
+
|
98
|
+
path = payload[:identifier]
|
99
|
+
if path
|
100
|
+
@_files[path] += 1
|
101
|
+
@_files[path.split("/").last] += 1
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def teardown_subscriptions
|
107
|
+
ActiveSupport::Notifications.unsubscribe("render_template.action_view")
|
108
|
+
ActiveSupport::Notifications.unsubscribe("!render_template.action_view")
|
109
|
+
end
|
110
|
+
|
66
111
|
end
|
67
112
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module SelfSysteem
|
2
|
+
class InstanceVariablesBuilder
|
3
|
+
include ActionView::Helpers::NumberHelper
|
4
|
+
|
5
|
+
attr_reader :controller, :relevant_instance_varaibles, :instance_variable_objects
|
6
|
+
|
7
|
+
def initialize(controller)
|
8
|
+
@controller = controller
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
build_variables
|
13
|
+
self
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_variables
|
17
|
+
@relevant_instance_varaibles = controller
|
18
|
+
.instance_variable_names.reject {|v| v[/@_/] || v == "@marked_for_same_origin_verification"}
|
19
|
+
@instance_variable_objects = {}
|
20
|
+
relevant_instance_varaibles.each do |v|
|
21
|
+
iv_val = controller.instance_variable_get(v)
|
22
|
+
if iv_val.class.name.match(/ActiveRecord::AssociationRelation|ActiveRecord::Associations::CollectionProxy/)
|
23
|
+
instance_variable_objects.merge!(v.to_s => { })
|
24
|
+
iv_val.each do |o|
|
25
|
+
instance_variable_objects[v.to_s].merge!(o.attributes.select {|k, v| k.to_s.match(/^id|_id/)})
|
26
|
+
end
|
27
|
+
elsif iv_val.respond_to?(:attributes)
|
28
|
+
instance_variable_objects.merge!({ v.to_s => iv_val.attributes.select {|k, v| k.to_s.match(/^id|_id/)} })
|
29
|
+
elsif iv_val.present? && iv_val.class.ancestors.select {|c| c.to_s.match(/ActiveModel|ActiveRecord/)}.present? && iv_val.is_a?(Symbol) != true
|
30
|
+
instance_variable_objects.merge!({ v.to_s => slice_hash(JSON.parse(iv_val.to_json), /^id|_id/) })
|
31
|
+
elsif iv_val.respond_to?(:instance_values)
|
32
|
+
instance_variable_objects.merge!({ v.to_s => iv_val.instance_values.select {|k, v| k.to_s.match(/^id|_id/)} })
|
33
|
+
else
|
34
|
+
instance_variable_objects.merge!({ v.to_s => iv_val.to_s })
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def transform_hash(original, options={}, &block)
|
40
|
+
original.inject({}){|result, (key,value)|
|
41
|
+
value = if (options[:deep] && Hash === value)
|
42
|
+
transform_hash(value, options, &block)
|
43
|
+
else
|
44
|
+
value
|
45
|
+
end
|
46
|
+
block.call(result,key,value)
|
47
|
+
result
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def slice_hash(hash, regex)
|
52
|
+
transform_hash(hash, :deep => true) {|hash, key, value|
|
53
|
+
hash[key] = value if (value.is_a?(Hash) || key.to_s.match(regex) )
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.call(controller)
|
58
|
+
new(controller).call
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
data/lib/self_systeem/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: self_systeem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Piccolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- lib/generators/self_systeem/test_generator.rb
|
70
70
|
- lib/self_systeem.rb
|
71
71
|
- lib/self_systeem/affirmation_builder.rb
|
72
|
+
- lib/self_systeem/instance_variables_builder.rb
|
72
73
|
- lib/self_systeem/version.rb
|
73
74
|
- self_systeem.gemspec
|
74
75
|
homepage: ''
|