capyspy 0.0.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +1 -0
- data/capyspy.gemspec +25 -0
- data/lib/capyspy.rb +11 -0
- data/lib/capyspy/dsl.rb +7 -0
- data/lib/capyspy/matchers.rb +16 -0
- data/lib/capyspy/spy.rb +70 -0
- data/lib/capyspy/version.rb +3 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7629cd6a81c555d66ec430e2ecb76e1bd8c6611a
|
4
|
+
data.tar.gz: 86fbfa93525b6c4ba1e1bcf17dd71e8632ab5f2d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f3d3416ce762bbebf2dd53758f34748699f7426d92acf1545fc99374ac848f7d6d2535c94b61e7a318efdac6af68721490c954706b1838d7148d0953e69b5741
|
7
|
+
data.tar.gz: 1a2cb0a66446792818b290d060a3dcebaf83102c10167eaac776eb9605ea55b0fb26ca2d2ce15cce00fc041f32d9fa4a673ded544d751869c85e91296e93c5c2
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Capyspy
|
2
|
+
|
3
|
+
Mock js objects with capybara
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capyspy', group: :test
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capyspy
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
describe 'Details page', js: true do
|
22
|
+
it 'should share article' do
|
23
|
+
spy = spy_on 'share'
|
24
|
+
|
25
|
+
page.evaluate_script 'share()'
|
26
|
+
|
27
|
+
expect(spy).to have_been_called
|
28
|
+
expect('share').to have_been_called
|
29
|
+
expect(spy.calls).to have(1).item
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should delete article after confirm' do
|
33
|
+
spy = spy_on('confirm').and_return true
|
34
|
+
|
35
|
+
click_button 'Delete'
|
36
|
+
|
37
|
+
expect(spy).to have_been_called
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should publish article' do
|
41
|
+
spy = spy_on('alert').and_call_through
|
42
|
+
|
43
|
+
click_button 'Publish'
|
44
|
+
|
45
|
+
expect(spy).to have_been_called
|
46
|
+
expect(spy.calls.last).to include 'You item was published'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should share via facebook' do
|
50
|
+
spy = spy_on('fbShare').and_call_fake 'function (id) { shareToFb(id); }'
|
51
|
+
|
52
|
+
click_button 'Share via FB'
|
53
|
+
|
54
|
+
expect(spy).to have_been_called
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/capyspy.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'capyspy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "capyspy"
|
8
|
+
spec.version = Capyspy::VERSION
|
9
|
+
spec.authors = ["Tima Maslyuchenko "]
|
10
|
+
spec.email = ["insside@gmail.com"]
|
11
|
+
spec.description = %q{Mock js objects with capybara}
|
12
|
+
spec.summary = %q{Mock js objects with capybara}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "capybara"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/capyspy.rb
ADDED
data/lib/capyspy/dsl.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rspec/expectations'
|
2
|
+
|
3
|
+
RSpec::Matchers.define :have_been_called do
|
4
|
+
match do |actual|
|
5
|
+
spy = actual.is_a?(Capyspy::Spy) ? actual : Capyspy::Spy.new(page, actual)
|
6
|
+
spy.calls.present?
|
7
|
+
end
|
8
|
+
|
9
|
+
failure_message_for_should do |actual|
|
10
|
+
"expected #{actual.to_s} to have been called"
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message_for_should_not do |actual|
|
14
|
+
"expected #{actual.to_s} not to have been called"
|
15
|
+
end
|
16
|
+
end
|
data/lib/capyspy/spy.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
module Capyspy
|
2
|
+
class Spy
|
3
|
+
attr_reader :page, :method
|
4
|
+
|
5
|
+
def initialize(page, method)
|
6
|
+
@page = page
|
7
|
+
@method = method.to_s
|
8
|
+
|
9
|
+
init
|
10
|
+
end
|
11
|
+
|
12
|
+
def and_call_through
|
13
|
+
with_spy 'callThrough = true'
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def and_return(value)
|
18
|
+
with_spy 'callThrough = false', "fake = function() { return #{value.to_json}; }"
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def and_call_fake(function)
|
23
|
+
with_spy 'callThrough = false', "fake = #{function}"
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
def calls
|
28
|
+
with_spy 'calls'
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_s
|
32
|
+
method
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def init
|
38
|
+
page.evaluate_script <<JS
|
39
|
+
(function() {
|
40
|
+
window._capyspy = window._capyspy || {};
|
41
|
+
if (!window._capyspy['#{method}']) {
|
42
|
+
window._capyspy['#{method}'] = {
|
43
|
+
callThrough: false,
|
44
|
+
calls: [],
|
45
|
+
fake: function() {},
|
46
|
+
original: window.#{method}
|
47
|
+
};
|
48
|
+
|
49
|
+
window.#{method} = function() {
|
50
|
+
var spy = window._capyspy['#{method}'];
|
51
|
+
spy.calls.push(Array.prototype.slice.call(arguments, 0));
|
52
|
+
if (spy.callThrough) {
|
53
|
+
return spy.original.apply(this, arguments);
|
54
|
+
} else {
|
55
|
+
return spy.fake.apply(this, arguments);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
})();
|
60
|
+
JS
|
61
|
+
end
|
62
|
+
|
63
|
+
def with_spy(*expressions)
|
64
|
+
raise ArgumentError if expressions.empty?
|
65
|
+
expressions.each do |expression|
|
66
|
+
page.evaluate_script "window._capyspy['#{method}'].#{expression};"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: capyspy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 'Tima Maslyuchenko '
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capybara
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Mock js objects with capybara
|
56
|
+
email:
|
57
|
+
- insside@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- capyspy.gemspec
|
68
|
+
- lib/capyspy.rb
|
69
|
+
- lib/capyspy/dsl.rb
|
70
|
+
- lib/capyspy/matchers.rb
|
71
|
+
- lib/capyspy/spy.rb
|
72
|
+
- lib/capyspy/version.rb
|
73
|
+
homepage: ''
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Mock js objects with capybara
|
97
|
+
test_files: []
|