wist 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/test/test.js ADDED
@@ -0,0 +1,32 @@
1
+ $('#click_test').click(function() {
2
+ $(this).text('clicked');
3
+ });
4
+
5
+ $('#wait_test').click(function() {
6
+ var $this = $(this);
7
+
8
+ setTimeout(function(){
9
+ $this.text('clicked');
10
+ }, 1000);
11
+ });
12
+
13
+ $('#enable_tweet_button').click(function() {
14
+ !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
15
+ });
16
+
17
+ $('#alert_test').click(function() {
18
+ alert('alert');
19
+ });
20
+
21
+ $('#test_wait_til_element_visible').click(function() {
22
+ var $this = $(this);
23
+ $this.hide();
24
+
25
+ setTimeout(function() {
26
+ $this.show();
27
+ }, 1000);
28
+ });
29
+
30
+ $('#test_set_value_and_trigger_evts').change(function () {
31
+ $(this).val('changed');
32
+ });
data/test/test0.html ADDED
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ <button id='click_test'>foo</button>
7
+ <button id='wait_test'>foo</button>
8
+ <button id='enable_tweet_button'>foo</button>
9
+ <a href="https://twitter.com/share" class="twitter-share-button" data-text='check this out'></a>
10
+ <a id='switch_window_test' href='test1.html' target='_blank'>foo</a>
11
+ <input id='input_test' type='text' />
12
+
13
+ <div id='class_test' class='foo bar'></div>
14
+ <button id='alert_test'>foo</button>
15
+
16
+ <div id='invisible' style='display:none;'></div>
17
+
18
+ <a id='wait_for_new_url_test' href='test1.html'>foo</a>
19
+
20
+ <button id='test_wait_til_element_visible'>bar</button>
21
+
22
+ <input id='test_set_value_and_trigger_evts' type='text' />
23
+
24
+ <script src="jquery.js"></script>
25
+ <script src="test.js"></script>
26
+ </body>
27
+ </html>
data/test/test1.html ADDED
@@ -0,0 +1,7 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ </head>
5
+ <body>
6
+ </body>
7
+ </html>
@@ -0,0 +1,21 @@
1
+ require 'capybara'
2
+ require 'capybara/poltergeist'
3
+ require 'wist'
4
+ require 'pry'
5
+ begin; require 'turn/autorun'; rescue LoadError; end
6
+ Turn.config.format = :dot
7
+
8
+ class CapybaraTestCase < Test::Unit::TestCase
9
+ include Capybara::DSL
10
+ include Wist
11
+
12
+ def setup
13
+ Capybara.javascript_driver = ENV['BROWSER'].to_sym if ENV['BROWSER']
14
+ Capybara.current_driver = Capybara.javascript_driver
15
+ end
16
+
17
+ def teardown
18
+ Capybara.reset_sessions!
19
+ Capybara.use_default_driver
20
+ end
21
+ end
@@ -0,0 +1,94 @@
1
+ require 'test_helper'
2
+
3
+ class TestWist < CapybaraTestCase
4
+ def setup
5
+ super
6
+ visit "file://#{Dir.pwd}/test/test0.html"
7
+ end
8
+
9
+ # helpers
10
+ def verify_test_page(num)
11
+ assert current_path.match(/test#{num}.html$/)
12
+ end
13
+
14
+ # tests
15
+ def test_click
16
+ click '#click_test'
17
+ assert_equal 'clicked', find('#click_test').text
18
+ end
19
+
20
+ def test_wait_until
21
+ button = find('#wait_test')
22
+ button.click
23
+ assert button.text != 'clicked'
24
+ wait_until { button.text == 'clicked' }
25
+ end
26
+
27
+ def test_verify_tweet_button
28
+ click '#enable_tweet_button'
29
+ verify_tweet_button 'check this out'
30
+ end
31
+
32
+ def test_switch_to_window_and_execute
33
+ return if Capybara.javascript_driver == :poltergeist
34
+ verify_test_page 0
35
+ click '#switch_window_test'
36
+
37
+ switch_to_window_and_execute do
38
+ verify_test_page 1
39
+ end
40
+
41
+ verify_test_page 0
42
+ end
43
+
44
+ def test_get_js
45
+ assert get_js('document.URL').match(/test0.html$/)
46
+ end
47
+
48
+ def test_get_val
49
+ find('#input_test').set 'foo'
50
+ assert_equal 'foo', get_val('#input_test')
51
+ end
52
+
53
+ def test_has_class
54
+ %w(foo bar).each { |c| assert has_class('#class_test', c) }
55
+ assert_equal false, has_class('#class_test', 'baz')
56
+ end
57
+
58
+ def test_alert_accept
59
+ alert_accept 'alert' do
60
+ click '#alert_test'
61
+ end
62
+ end
63
+
64
+ def test_wait_for_new_url
65
+ verify_test_page 0
66
+ wait_for_new_url find('#wait_for_new_url_test')
67
+ verify_test_page 1
68
+ end
69
+
70
+ def test_refresh
71
+ find('#input_test').set 'foo'
72
+ refresh
73
+ assert_equal '', get_val('#input_test')
74
+ end
75
+
76
+ def test_element_displayed?
77
+ assert_equal false, element_displayed?('#invisible')
78
+ assert element_displayed?('#input_test')
79
+ end
80
+
81
+ def test_wait_til_element_visible
82
+ el = find('#test_wait_til_element_visible')
83
+ el.click
84
+ assert_equal false, el.visible?
85
+
86
+ assert wait_til_element_visible('#test_wait_til_element_visible').visible?
87
+ end
88
+
89
+ def test_set_value_and_trigger_evts
90
+ set_value_and_trigger_evts('#test_set_value_and_trigger_evts', 'foo')
91
+ assert_equal('changed', get_val('#test_set_value_and_trigger_evts'))
92
+ end
93
+
94
+ end
data/wist.gemspec ADDED
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'wist'
3
+ gem.version = '0.0.2'
4
+ gem.summary = 'capybara helpers'
5
+ gem.author = 'Lihan Li'
6
+ gem.email = 'frankieteardrop@gmail.com'
7
+ gem.homepage = 'http://github.com/lihanli/wist'
8
+
9
+ gem.add_dependency 'capybara'
10
+
11
+ gem.files = `git ls-files`.split("\n")
12
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
13
+ gem.require_paths = ["lib"]
14
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wist
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lihan Li
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capybara
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description:
31
+ email: frankieteardrop@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - MIT-LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - lib/wist.rb
42
+ - test/jquery.js
43
+ - test/test.js
44
+ - test/test0.html
45
+ - test/test1.html
46
+ - test/test_helper.rb
47
+ - test/tests/wist_test.rb
48
+ - wist.gemspec
49
+ homepage: http://github.com/lihanli/wist
50
+ licenses: []
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 1.8.23
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: capybara helpers
73
+ test_files:
74
+ - test/jquery.js
75
+ - test/test.js
76
+ - test/test0.html
77
+ - test/test1.html
78
+ - test/test_helper.rb
79
+ - test/tests/wist_test.rb