taperecorder 0.1.0
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 +7 -0
- data/.gitignore +49 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/app/views/_taperecorder_html.html.erb +30 -0
- data/app/views/_taperecorder_js.js.erb +265 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/taperecorder.rb +10 -0
- data/lib/taperecorder/engine.rb +2 -0
- data/lib/taperecorder/middleware.rb +92 -0
- data/lib/taperecorder/rails.rb +8 -0
- data/lib/taperecorder/version.rb +3 -0
- data/taperecorder.gemspec +32 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1134cad52ecd77e091284b351dbd4908a46a0f35
|
4
|
+
data.tar.gz: 4e58095b512cced2a06a96db2e7ed3d9b5fd78f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 005745a8b955afd344c1d0971c6c2e227fb23c025c1842ab122a74119c403aa631d902e3d36e003e77b229dad5b5b785524c511210081c2b565d488ab3501bb4
|
7
|
+
data.tar.gz: 3463111b3e6e499eabc13420d30625e83432177a2b3d4d688e581c710e67fad59f4c7186a0c3d57b32bf49846a1686e97e2f11a3fb5e36c530da4b39ac5df73e
|
data/.gitignore
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/.yardoc
|
5
|
+
/_yardoc/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/log
|
10
|
+
/tmp
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
/public/system
|
14
|
+
/coverage/
|
15
|
+
/spec/tmp
|
16
|
+
**.orig
|
17
|
+
rerun.txt
|
18
|
+
pickle-email-*.html
|
19
|
+
|
20
|
+
# TODO Comment out these rules if you are OK with secrets being uploaded to the repo
|
21
|
+
config/initializers/secret_token.rb
|
22
|
+
config/secrets.yml
|
23
|
+
|
24
|
+
# dotenv
|
25
|
+
# TODO Comment out this rule if environment variables can be committed
|
26
|
+
.env
|
27
|
+
|
28
|
+
## Environment normalization:
|
29
|
+
/.bundle
|
30
|
+
/vendor/bundle
|
31
|
+
|
32
|
+
# these should all be checked in to normalize the environment:
|
33
|
+
Gemfile.lock
|
34
|
+
.ruby-version
|
35
|
+
.ruby-gemset
|
36
|
+
|
37
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
38
|
+
.rvmrc
|
39
|
+
|
40
|
+
# if using bower-rails ignore default bower_components path bower.json files
|
41
|
+
/vendor/assets/bower_components
|
42
|
+
*.bowerrc
|
43
|
+
bower.json
|
44
|
+
|
45
|
+
# Ignore pow environment settings
|
46
|
+
.powenv
|
47
|
+
|
48
|
+
# Ignore Byebug command history file.
|
49
|
+
.byebug_history
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at TODO: Write your email address. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Siddhartha Mukherjee
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# Taperecorder
|
2
|
+
Create cucumber steps by simply clicking arround...
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'taperecorder'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install taperecorder
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Just simply include the gem, you will see a green button in left bottom corner of your browser and then just click on the green start record button.
|
23
|
+
When you have done navigating the scenario, click the button again.
|
24
|
+
|
25
|
+
See it action below. Recording of a login screen.
|
26
|
+
|
27
|
+
[](http://www.youtube.com/watch?v=Esn609cHoMQ)
|
28
|
+
|
29
|
+
## Development
|
30
|
+
|
31
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
+
|
33
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/taperecorder. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
38
|
+
|
39
|
+
|
40
|
+
## License
|
41
|
+
|
42
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
<style type="text/css">
|
2
|
+
#taperecorder_html{
|
3
|
+
position: fixed;
|
4
|
+
bottom: 40px;
|
5
|
+
left: 10px;
|
6
|
+
z-index: 9999999999;
|
7
|
+
background: #c0c0c0;
|
8
|
+
padding: 5px;
|
9
|
+
border: solid 1px #e0e0e0;
|
10
|
+
}
|
11
|
+
#taperecorder_html button{
|
12
|
+
font-size: 2em;
|
13
|
+
padding: 5px;
|
14
|
+
}
|
15
|
+
|
16
|
+
#taperecorder_start{
|
17
|
+
color: #000;
|
18
|
+
background: green;
|
19
|
+
display: block;
|
20
|
+
}
|
21
|
+
#taperecorder_stop{
|
22
|
+
color: #fff;
|
23
|
+
background: red;
|
24
|
+
display: none;
|
25
|
+
}
|
26
|
+
</style>
|
27
|
+
<div id="taperecorder_html" class="taperecorder">
|
28
|
+
<button id="taperecorder_start" onclick="Taperecorder.start()" class="taperecorder">⛄</button>
|
29
|
+
<button id="taperecorder_stop" onclick="Taperecorder.stop()" class="taperecorder">⛇</button>
|
30
|
+
</div>
|
@@ -0,0 +1,265 @@
|
|
1
|
+
//Steps that Taperecorder can record
|
2
|
+
// Given I am on <page_name>
|
3
|
+
|
4
|
+
// When/And I press <button>
|
5
|
+
// When/And I follow <link>
|
6
|
+
// When/And I fill in <field> with <value>
|
7
|
+
// When/And I select <value> from <field>
|
8
|
+
// When/And I check <field>
|
9
|
+
// When/And I uncheck <field>
|
10
|
+
// When/And I choose <field>
|
11
|
+
// When/And I attach the file <path> to <field>
|
12
|
+
|
13
|
+
// Then/And I should see <text>
|
14
|
+
// Then/And I should not see <text>
|
15
|
+
// Then/And I should be on <page_name>
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// JS Hack
|
20
|
+
Element.prototype._addEventListener = Element.prototype.addEventListener;
|
21
|
+
Element.prototype.addEventListener = function(a,b,c) {
|
22
|
+
var _classes = this.getAttribute("class") || "";
|
23
|
+
this.setAttribute("class", _classes+" taperecorder_capture");
|
24
|
+
this._addEventListener(a,b,c);
|
25
|
+
};
|
26
|
+
|
27
|
+
|
28
|
+
//Taperecorder is singleton
|
29
|
+
var Taperecorder = new function() {
|
30
|
+
var _tape = this;
|
31
|
+
|
32
|
+
//started/stopped
|
33
|
+
_tape.status = function(_set_status) {
|
34
|
+
var _status = _tape.getCookie('taperecorder') || "";
|
35
|
+
|
36
|
+
if(_tape.is_blank(_status)){
|
37
|
+
_tape.setCookie('taperecorder', 'stopped', 1);
|
38
|
+
_status = 'stopped';
|
39
|
+
}
|
40
|
+
if(_set_status=='stopped' || _set_status=='started'){
|
41
|
+
_tape.setCookie('taperecorder', _set_status, 1);
|
42
|
+
_status = _set_status;
|
43
|
+
}
|
44
|
+
return _status;
|
45
|
+
};
|
46
|
+
_tape.start = function() {
|
47
|
+
console.log("Starting Taperecorder...");
|
48
|
+
|
49
|
+
_tape.status('started');
|
50
|
+
|
51
|
+
_tape.bindClickEvents();
|
52
|
+
_tape.bindFocusEvents();
|
53
|
+
_tape.bindBlurEvents();
|
54
|
+
|
55
|
+
document.getElementById('taperecorder_start').style.display = "none";
|
56
|
+
document.getElementById('taperecorder_stop').style.display = "block";
|
57
|
+
|
58
|
+
if(_tape.scenario_present()){
|
59
|
+
_tape.step("Then", "I should be on", window.location.pathname);
|
60
|
+
}else{
|
61
|
+
_tape.step("Given", "I am on", window.location.pathname);
|
62
|
+
}
|
63
|
+
|
64
|
+
_tape.event_lock = false;
|
65
|
+
_tape.lock_manager = setInterval(function(){
|
66
|
+
_tape.event_lock = false;
|
67
|
+
}, 1000);
|
68
|
+
};
|
69
|
+
_tape.stop = function() {
|
70
|
+
console.log("Stoping Taperecorder...");
|
71
|
+
|
72
|
+
_tape.step("Then", "I should be on", window.location.pathname);
|
73
|
+
_tape.step("Then", "I should see", "<replace this with a text you see in page>");
|
74
|
+
_tape.step("Then", "I should not see", "<replace this with a text you see in page>");
|
75
|
+
|
76
|
+
clearInterval(_tape.lock_manager);
|
77
|
+
|
78
|
+
document.getElementById('taperecorder_start').style.display = "block";
|
79
|
+
document.getElementById('taperecorder_stop').style.display = "none";
|
80
|
+
|
81
|
+
_tape.status('stopped');
|
82
|
+
|
83
|
+
_tape.flush();
|
84
|
+
};
|
85
|
+
|
86
|
+
|
87
|
+
_tape.scenario_present = function(){
|
88
|
+
var taperecorder_scenario = localStorage.taperecorder_scenario || "";
|
89
|
+
if(_tape.is_blank(taperecorder_scenario)){
|
90
|
+
return false;
|
91
|
+
}
|
92
|
+
return true;
|
93
|
+
};
|
94
|
+
|
95
|
+
_tape.lastkey_present = function(){
|
96
|
+
var taperecorder_lastkey = localStorage.taperecorder_lastkey || "";
|
97
|
+
if(_tape.is_blank(taperecorder_lastkey)){
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
return true;
|
101
|
+
};
|
102
|
+
//Flush existing steps from storage and show it in browser
|
103
|
+
_tape.flush = function() {
|
104
|
+
console.log("Flushing all steps...");
|
105
|
+
alert(localStorage.taperecorder_scenario);
|
106
|
+
localStorage.taperecorder_scenario = null;
|
107
|
+
localStorage.taperecorder_lastkey = null;
|
108
|
+
};
|
109
|
+
//Add a step to local storage
|
110
|
+
_tape.step = function(_key, _action, _field, _keyword,_value) {
|
111
|
+
//Lock
|
112
|
+
_tape.event_lock = true;
|
113
|
+
|
114
|
+
//Sanitize
|
115
|
+
_action = _tape.trim(_action);
|
116
|
+
_field = _tape.trim(_field);
|
117
|
+
if(!_tape.is_blank(_value))
|
118
|
+
_value = _tape.trim(_value);
|
119
|
+
if(!_tape.is_blank(_keyword))
|
120
|
+
_keyword = _tape.trim(_keyword);
|
121
|
+
|
122
|
+
var taperecorder_scenario = localStorage.taperecorder_scenario || "";
|
123
|
+
|
124
|
+
var taperecorder_laststep = localStorage.taperecorder_laststep || "";
|
125
|
+
var taperecorder_lastkey = localStorage.taperecorder_lastkey || "";
|
126
|
+
|
127
|
+
|
128
|
+
if(!_tape.scenario_present()){
|
129
|
+
taperecorder_scenario = "Scenario: Generated by Taperecorder, Please replace this line with actual Scenario.\n\n";
|
130
|
+
}
|
131
|
+
if(!_tape.lastkey_present()){
|
132
|
+
taperecorder_lastkey = "Given";
|
133
|
+
}
|
134
|
+
if(_tape.lastkey_present() && taperecorder_lastkey==_key){
|
135
|
+
taperecorder_lastkey = "And";
|
136
|
+
}else{
|
137
|
+
taperecorder_lastkey = _key;
|
138
|
+
}
|
139
|
+
|
140
|
+
if(!_tape.is_blank(_keyword) && !_tape.is_blank(_value)){
|
141
|
+
var _step = _action + " \"" + _field + "\" " + _keyword + " \"" + _value + "\" " + "\n";
|
142
|
+
}else{
|
143
|
+
var _step = _action + " \"" + _field + "\" " + "\n";
|
144
|
+
}
|
145
|
+
if (localStorage.taperecorder_laststep == _step)
|
146
|
+
return;
|
147
|
+
|
148
|
+
taperecorder_scenario = taperecorder_scenario + taperecorder_lastkey + " " + _step;
|
149
|
+
|
150
|
+
localStorage.taperecorder_scenario = taperecorder_scenario;
|
151
|
+
localStorage.taperecorder_laststep = _step;
|
152
|
+
localStorage.taperecorder_lastkey = _key;
|
153
|
+
|
154
|
+
console.log("Step added: "+taperecorder_scenario);
|
155
|
+
};
|
156
|
+
|
157
|
+
//Events
|
158
|
+
_tape.bindClickEvents = function() {
|
159
|
+
console.log("Binding Taperecorder click events...");
|
160
|
+
document.addEventListener('click', function(e) {
|
161
|
+
e = e || window.event
|
162
|
+
var target = e.target || e.srcElement;
|
163
|
+
if(!_tape.event_lock && !_tape.hasClass(target, 'taperecorder')){
|
164
|
+
if(/a/i.test( target.nodeName )){
|
165
|
+
_tape.step("When", "I follow", _tape.getTextOrId(target));
|
166
|
+
}else if(/button/i.test( target.nodeName )){
|
167
|
+
_tape.step("When", "I press", _tape.getTextOrId(target));
|
168
|
+
}else if(_tape.hasClass(target, 'taperecorder_capture')){
|
169
|
+
_tape.step("When", "I press", _tape.getTextOrId(target));
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}, true);
|
173
|
+
};
|
174
|
+
_tape.bindFocusEvents = function() {
|
175
|
+
console.log("Binding Taperecorder focus events...");
|
176
|
+
document.addEventListener('focus', function(e) {
|
177
|
+
e = e || window.event
|
178
|
+
var target = e.target || e.srcElement;
|
179
|
+
if(/input|textarea/i.test( target.nodeName ))
|
180
|
+
_tape.last_input = target;
|
181
|
+
}, true);
|
182
|
+
};
|
183
|
+
_tape.bindBlurEvents = function() {
|
184
|
+
console.log("Binding Taperecorder blur events...");
|
185
|
+
document.addEventListener('blur', function(e) {
|
186
|
+
if(!_tape.is_blank(_tape.last_input))
|
187
|
+
_tape.create_step_for_field(_tape.last_input);
|
188
|
+
}, true);
|
189
|
+
};
|
190
|
+
_tape.create_step_for_field = function(element){
|
191
|
+
if(!(/file|checkbox|radio/i.test( element.getAttribute('type') )) || element.nodeName=="textarea")
|
192
|
+
_tape.step("When", "I fill in", _tape.getTextOrId(element), "with", _tape.getValue(element));
|
193
|
+
else if(/file/i.test( element.getAttribute('type') ))
|
194
|
+
_tape.step("When", "I attach the file", _tape.getValue(element), "to", _tape.getTextOrId(element));
|
195
|
+
else if(/checkbox/i.test( element.getAttribute('type') ))
|
196
|
+
if(element.checked == true)
|
197
|
+
_tape.step("When", "I check", _tape.getTextOrId(element));
|
198
|
+
else
|
199
|
+
_tape.step("When", "I uncheck", _tape.getTextOrId(element));
|
200
|
+
else if(/radio/i.test( element.getAttribute('type') ) && element.checked == true)
|
201
|
+
_tape.step("When", "I choose", _tape.getTextOrId(element));
|
202
|
+
_tape.last_input = null;
|
203
|
+
};
|
204
|
+
|
205
|
+
//Utilities
|
206
|
+
_tape.is_blank = function(txt){
|
207
|
+
if(typeof txt == typeof undefined || txt == null || txt == "" || txt == "undefined" || txt == "null"){
|
208
|
+
return true;
|
209
|
+
}
|
210
|
+
return false;
|
211
|
+
};
|
212
|
+
_tape.trim = function(str){
|
213
|
+
return str.replace(/(\r\n|\n|\r)/gm,"").trim();
|
214
|
+
};
|
215
|
+
_tape.getValue = function(element) {
|
216
|
+
return element.value;
|
217
|
+
};
|
218
|
+
_tape.getTextOrId = function(element) {
|
219
|
+
var txt = element.textContent || element.innerText;
|
220
|
+
txt = _tape.trim(txt);
|
221
|
+
if(_tape.is_blank(txt)){
|
222
|
+
txt = element.id || element.getAttribute('name');
|
223
|
+
}
|
224
|
+
return txt;
|
225
|
+
};
|
226
|
+
_tape.getLabelTextOrId = function(element) {
|
227
|
+
var idVal = element.id;
|
228
|
+
labels = document.getElementsByTagName('label');
|
229
|
+
for( var i = 0; i < labels.length; i++ ) {
|
230
|
+
if (labels[i].htmlFor == idVal)
|
231
|
+
return labels[i].textContent || labels[i].innerText;
|
232
|
+
}
|
233
|
+
return element.id || element.getAttribute('name');
|
234
|
+
};
|
235
|
+
_tape.hasClass = function(element, cls) {
|
236
|
+
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
|
237
|
+
};
|
238
|
+
|
239
|
+
_tape.setCookie = function(cname, cvalue, exdays) {
|
240
|
+
var d = new Date();
|
241
|
+
d.setTime(d.getTime() + (exdays*24*60*60*1000));
|
242
|
+
var expires = "expires="+ d.toUTCString();
|
243
|
+
document.cookie = cname + "=" + cvalue + "; " + expires;
|
244
|
+
};
|
245
|
+
_tape.getCookie = function(cname) {
|
246
|
+
var name = cname + "=";
|
247
|
+
var ca = document.cookie.split(';');
|
248
|
+
for(var i = 0; i <ca.length; i++) {
|
249
|
+
var c = ca[i];
|
250
|
+
while (c.charAt(0)==' ') {
|
251
|
+
c = c.substring(1);
|
252
|
+
}
|
253
|
+
if (c.indexOf(name) == 0) {
|
254
|
+
return c.substring(name.length,c.length);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
return "";
|
258
|
+
};
|
259
|
+
};
|
260
|
+
|
261
|
+
|
262
|
+
jQuery(document).ready(function(){
|
263
|
+
if(Taperecorder.scenario_present())
|
264
|
+
Taperecorder.start();
|
265
|
+
});
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "taperecorder"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/taperecorder.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "json"
|
2
|
+
require "active_support/all"
|
3
|
+
require_relative "taperecorder/version"
|
4
|
+
require_relative "taperecorder/middleware"
|
5
|
+
|
6
|
+
if defined?(Rails) && Rails.env.development?
|
7
|
+
require "taperecorder/engine"
|
8
|
+
end
|
9
|
+
|
10
|
+
require "taperecorder/rails" if defined?(Rails)
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module Taperecorder
|
2
|
+
|
3
|
+
# This middleware is responsible for injecting taperecorder.js
|
4
|
+
class Middleware
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
# Inject taperecorder.js and friends if this is a successful HTML response
|
11
|
+
status, headers, response = @app.call(env)
|
12
|
+
|
13
|
+
if html_headers?(status, headers) && body = response_body(response)
|
14
|
+
#insert after jquery
|
15
|
+
inject_taperecorder_js!(body, 'jquery')
|
16
|
+
inject_taperecorder_html!(body)
|
17
|
+
|
18
|
+
content_length = body.bytesize.to_s
|
19
|
+
|
20
|
+
# For rails v4.2.0+ compatibility
|
21
|
+
if defined?(ActionDispatch::Response::RackBody) && ActionDispatch::Response::RackBody === response
|
22
|
+
response = response.instance_variable_get(:@response)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Modifying the original response obj maintains compatibility with other middlewares
|
26
|
+
if ActionDispatch::Response === response
|
27
|
+
response.body = [body]
|
28
|
+
response.header['Content-Length'] = content_length unless committed?(response)
|
29
|
+
response.to_a
|
30
|
+
else
|
31
|
+
headers['Content-Length'] = content_length
|
32
|
+
[status, headers, [body]]
|
33
|
+
end
|
34
|
+
else
|
35
|
+
[status, headers, response]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def committed?(response)
|
42
|
+
response.respond_to?(:committed?) && response.committed?
|
43
|
+
end
|
44
|
+
|
45
|
+
def inject_taperecorder_js!(html, after_script_name)
|
46
|
+
html.sub!(/<script[^>].*#{after_script_name}.*<\/script>/x) { "#{$~}\n<script type=\"text/javascript\" >#{render_taperecorder_js}</script>" }
|
47
|
+
end
|
48
|
+
|
49
|
+
def inject_taperecorder_html!(html)
|
50
|
+
html.sub!(/<body[^>]*>/) { "#{$~}\n#{render_taperecorder_html}" }
|
51
|
+
end
|
52
|
+
|
53
|
+
def render_taperecorder_js
|
54
|
+
if ApplicationController.respond_to?(:render)
|
55
|
+
# Rails 5
|
56
|
+
ApplicationController.render(:partial => "/taperecorder_js").html_safe
|
57
|
+
else
|
58
|
+
# Rails <= 4.2
|
59
|
+
ac = ActionController::Base.new
|
60
|
+
ac.render_to_string(:partial => '/taperecorder_js').html_safe
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def render_taperecorder_html
|
65
|
+
if ApplicationController.respond_to?(:render)
|
66
|
+
# Rails 5
|
67
|
+
ApplicationController.render(:partial => "/taperecorder_html").html_safe
|
68
|
+
else
|
69
|
+
# Rails <= 4.2
|
70
|
+
ac = ActionController::Base.new
|
71
|
+
ac.render_to_string(:partial => '/taperecorder_html').html_safe
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def helper
|
76
|
+
ActionController::Base.helpers
|
77
|
+
end
|
78
|
+
|
79
|
+
def html_headers?(status, headers)
|
80
|
+
status == 200 &&
|
81
|
+
headers['Content-Type'] &&
|
82
|
+
headers['Content-Type'].include?('text/html') &&
|
83
|
+
headers["Content-Transfer-Encoding"] != "binary"
|
84
|
+
end
|
85
|
+
|
86
|
+
def response_body(response)
|
87
|
+
body = ''
|
88
|
+
response.each { |s| body << s.to_s }
|
89
|
+
body
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'taperecorder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "taperecorder"
|
8
|
+
spec.version = Taperecorder::VERSION
|
9
|
+
spec.authors = ["Siddhartha Mukherjee"]
|
10
|
+
spec.email = ["mukherjee.siddhartha@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Create cucumber steps by simply clicking arround...}
|
13
|
+
spec.description = %q{Create cucumber steps by simply clicking arround...}
|
14
|
+
spec.homepage = "https://github.com/siddhartham/taperecorder"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: taperecorder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Siddhartha Mukherjee
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Create cucumber steps by simply clicking arround...
|
42
|
+
email:
|
43
|
+
- mukherjee.siddhartha@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- app/views/_taperecorder_html.html.erb
|
55
|
+
- app/views/_taperecorder_js.js.erb
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/taperecorder.rb
|
59
|
+
- lib/taperecorder/engine.rb
|
60
|
+
- lib/taperecorder/middleware.rb
|
61
|
+
- lib/taperecorder/rails.rb
|
62
|
+
- lib/taperecorder/version.rb
|
63
|
+
- taperecorder.gemspec
|
64
|
+
homepage: https://github.com/siddhartham/taperecorder
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata:
|
68
|
+
allowed_push_host: https://rubygems.org
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.5.1
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Create cucumber steps by simply clicking arround...
|
89
|
+
test_files: []
|