wist 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org/'
2
+ gemspec
3
+
4
+ gem 'capybara', '2.0.2'
5
+ gem 'tconsole'
6
+ gem 'pry'
7
+ gem 'turn'
8
+ gem 'rake'
9
+ gem 'poltergeist', git: 'git://github.com/jonleighton/poltergeist.git'
data/Gemfile.lock ADDED
@@ -0,0 +1,79 @@
1
+ GIT
2
+ remote: git://github.com/jonleighton/poltergeist.git
3
+ revision: 98d4a4a8936e8d6b3417f2c057bafaba40874eee
4
+ specs:
5
+ poltergeist (1.0.2)
6
+ capybara (~> 2.0, >= 2.0.1)
7
+ faye-websocket (~> 0.4, >= 0.4.4)
8
+ http_parser.rb (~> 0.5.3)
9
+
10
+ PATH
11
+ remote: .
12
+ specs:
13
+ wist (0.0.1)
14
+ capybara
15
+
16
+ GEM
17
+ remote: http://rubygems.org/
18
+ specs:
19
+ addressable (2.3.2)
20
+ ansi (1.4.3)
21
+ capybara (2.0.2)
22
+ mime-types (>= 1.16)
23
+ nokogiri (>= 1.3.3)
24
+ rack (>= 1.0.0)
25
+ rack-test (>= 0.5.4)
26
+ selenium-webdriver (~> 2.0)
27
+ xpath (~> 1.0.0)
28
+ childprocess (0.3.6)
29
+ ffi (~> 1.0, >= 1.0.6)
30
+ coderay (1.0.8)
31
+ eventmachine (1.0.0)
32
+ faye-websocket (0.4.6)
33
+ eventmachine (>= 0.12.0)
34
+ ffi (1.3.1)
35
+ http_parser.rb (0.5.3)
36
+ libwebsocket (0.1.7.1)
37
+ addressable
38
+ websocket
39
+ method_source (0.8.1)
40
+ mime-types (1.19)
41
+ minitest (4.3.3)
42
+ multi_json (1.5.0)
43
+ nokogiri (1.5.6)
44
+ pry (0.9.10)
45
+ coderay (~> 1.0.5)
46
+ method_source (~> 0.8)
47
+ slop (~> 3.3.1)
48
+ rack (1.4.4)
49
+ rack-test (0.6.2)
50
+ rack (>= 1.0)
51
+ rake (10.0.3)
52
+ rubyzip (0.9.9)
53
+ selenium-webdriver (2.27.2)
54
+ childprocess (>= 0.2.5)
55
+ libwebsocket (~> 0.1.3)
56
+ multi_json (~> 1.0)
57
+ rubyzip
58
+ slop (3.3.3)
59
+ tconsole (1.2.7)
60
+ minitest (~> 4.3.0)
61
+ term-ansicolor (~> 1.0.7)
62
+ term-ansicolor (1.0.7)
63
+ turn (0.9.6)
64
+ ansi
65
+ websocket (1.0.6)
66
+ xpath (1.0.0)
67
+ nokogiri (~> 1.3)
68
+
69
+ PLATFORMS
70
+ ruby
71
+
72
+ DEPENDENCIES
73
+ capybara (= 2.0.2)
74
+ poltergeist!
75
+ pry
76
+ rake
77
+ tconsole
78
+ turn
79
+ wist!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Lihan Li
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ wist
2
+ ====
3
+
4
+ Some capybara helper functions I use often. Right now only working with Test::Unit. If anyone else is interested I can write some more documentation and get it working with RSpec.
data/Rakefile ADDED
@@ -0,0 +1,22 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new('test') do |t|
4
+ t.libs << "test"
5
+ t.test_files = FileList['test/tests/**/*.rb']
6
+ end
7
+
8
+ task 'test:all' do
9
+ Rake::Task['test'].execute
10
+
11
+ %w(chrome poltergeist).each do |browser|
12
+ ENV['BROWSER'] = browser
13
+ Rake::Task['test'].execute
14
+ end
15
+ end
16
+
17
+ task :build do
18
+ system 'gem build wist.gemspec'
19
+ `rm -rf build`
20
+ `mkdir build`
21
+ `mv *.gem build`
22
+ end
data/lib/wist.rb ADDED
@@ -0,0 +1,92 @@
1
+ module Wist
2
+
3
+ def self.included(base)
4
+ require 'selenium-webdriver'
5
+ require 'cgi'
6
+ Capybara.register_driver :chrome do |app|
7
+ Capybara::Selenium::Driver.new(app, browser: :chrome)
8
+ end
9
+ end
10
+
11
+ def wait_until(&block)
12
+ Selenium::WebDriver::Wait.new(timeout: defined?(@wait) ? @wait : 20).until &block
13
+ end
14
+
15
+ def click(selector)
16
+ find(selector).click
17
+ end
18
+
19
+ def set_value_and_trigger_evts(selector, val)
20
+ find(selector).set(val)
21
+ page.execute_script("$('#{selector}').focusout().change()")
22
+ end
23
+
24
+ def verify_tweet_button(text)
25
+ share_button_src = nil
26
+ wait_until { share_button_src = find('.twitter-share-button')[:src] }
27
+ assert_equal text, CGI.parse(URI.parse(share_button_src.gsub('#', '?')).query)['text'][0]
28
+ end
29
+
30
+ def driver
31
+ page.driver.browser
32
+ end
33
+
34
+ def switch_to_window_and_execute
35
+ wait_until { driver.window_handles.size == 2 }
36
+ within_window(driver.window_handles.last) do
37
+ yield
38
+ driver.close
39
+ end
40
+ end
41
+
42
+ def alert_accept(expected_msg = false)
43
+ page.execute_script "window.alert = function(msg) { window.lastAlertMsg = msg; }"
44
+ yield
45
+ assert_equal(expected_msg, get_js('window.lastAlertMsg')) if expected_msg
46
+ end
47
+
48
+ def get_js(code)
49
+ page.evaluate_script code
50
+ end
51
+
52
+ def jquery_selector(selector)
53
+ "$('#{selector}')"
54
+ end
55
+
56
+ def get_val(selector)
57
+ get_js "#{jquery_selector selector}.val()"
58
+ end
59
+
60
+ def has_class(selector, class_name)
61
+ get_js "#{jquery_selector selector}.hasClass('#{class_name}')"
62
+ end
63
+
64
+ def wait_for_new_url(element_to_click)
65
+ old_url = current_url
66
+ element_to_click.click
67
+ sleep 1
68
+ wait_until { current_url != old_url }
69
+ end
70
+
71
+ def refresh
72
+ visit current_url
73
+ end
74
+
75
+ def element_displayed?(selector)
76
+ find(selector).visible?
77
+ end
78
+
79
+ def wait_for_ajax
80
+ wait_until { get_js '$.isReady && ($.active == 0)' }
81
+ end
82
+
83
+ def wait_til_element_visible(selector)
84
+ el = nil
85
+ wait_until do
86
+ el = find(selector)
87
+ el.visible?
88
+ end
89
+ el
90
+ end
91
+
92
+ end