steam 0.0.4 → 0.0.5

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.
Files changed (42) hide show
  1. data/Gemfile +2 -0
  2. data/lib/core_ext/ruby/string/camelize.rb +1 -1
  3. data/lib/core_ext/ruby/string/underscore.rb +8 -1
  4. data/lib/steam/browser/html_unit.rb +9 -5
  5. data/lib/steam/browser/html_unit/client.rb +14 -2
  6. data/lib/steam/browser/html_unit/connection.rb +10 -10
  7. data/lib/steam/browser/html_unit/web_response.rb +0 -1
  8. data/lib/steam/connection/net_http.rb +4 -4
  9. data/lib/steam/java.rb +7 -6
  10. data/lib/steam/request.rb +88 -35
  11. data/lib/steam/session/rails.rb +1 -1
  12. data/lib/steam/version.rb +1 -1
  13. metadata +23 -50
  14. data/Rakefile +0 -23
  15. data/test/all.rb +0 -3
  16. data/test/browser/html_unit/actions_test.rb +0 -183
  17. data/test/browser/html_unit/javascript_test.rb +0 -60
  18. data/test/browser/html_unit/rails_actions_test.rb +0 -150
  19. data/test/browser/html_unit_test.rb +0 -98
  20. data/test/connection/cascade_test.rb +0 -42
  21. data/test/connection/mock_test.rb +0 -58
  22. data/test/connection/rails_test.rb +0 -16
  23. data/test/connection/static_test.rb +0 -14
  24. data/test/example/webrat_compat_steps_test.rb +0 -307
  25. data/test/fixtures/html_fakes.rb +0 -191
  26. data/test/java_test.rb +0 -29
  27. data/test/playground/connection.rb +0 -19
  28. data/test/playground/dragdrop_behavior.rb +0 -60
  29. data/test/playground/drb.rb +0 -55
  30. data/test/playground/java_signature.rb +0 -22
  31. data/test/playground/nokogiri.rb +0 -15
  32. data/test/playground/put_headers.rb +0 -83
  33. data/test/playground/rack.rb +0 -11
  34. data/test/playground/rjb_bind.rb +0 -42
  35. data/test/playground/stack_level_problem.rb +0 -129
  36. data/test/playground/thread_problem.rb +0 -57
  37. data/test/playground/web_response_data.rb +0 -21
  38. data/test/playground/webrat.rb +0 -48
  39. data/test/playground/xhr_accept_headers.rb +0 -61
  40. data/test/process_test.rb +0 -55
  41. data/test/session_test.rb +0 -40
  42. data/test/test_helper.rb +0 -80
@@ -1,57 +0,0 @@
1
- # require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
2
-
3
- $: << File.expand_path(File.dirname(__FILE__) + "/../../lib")
4
- require 'steam'
5
- include Steam
6
-
7
- Java.import 'com.gargoylesoftware.htmlunit.WebClient'
8
- Java.import 'com.gargoylesoftware.htmlunit.BrowserVersion'
9
- Java.import 'com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException'
10
-
11
- page = <<-erb
12
- <html>
13
- <head>
14
- <script>
15
- document.title = 'pre ajax call';
16
- function some_ajax(url) {
17
- http = new XMLHttpRequest();
18
- http.open("GET", url, true);
19
- http.onreadystatechange = function() {
20
- document.title = document.title + ' ' + http.readyState
21
- if(http.readyState == 4) document.title = http.responseText
22
- }
23
- http.send(null);
24
- }
25
- some_ajax('/ajax/1');
26
- // some_ajax('/ajax/2');
27
- </script>
28
- </head>
29
- </html>
30
- erb
31
-
32
- client = Java::WebClient.new(Java::BrowserVersion.FIREFOX_3)
33
- client.setCssEnabled(true)
34
- client.setJavaScriptEnabled(true)
35
-
36
- mock = Connection::Mock.new
37
- mock.mock :get, 'http://localhost:3000/', page
38
- mock.mock :get, 'http://localhost:3000/ajax/1', 'post ajax call 1!', 'Content-Type' => 'application/javascript'
39
- # mock.mock :get, 'http://localhost:3000/ajax/2', 'post ajax call 2!', 'Content-Type' => 'application/javascript'
40
-
41
- connection = Browser::HtmlUnit::Connection.new(mock)
42
- client.setWebConnection(Rjb::bind(connection, 'com.gargoylesoftware.htmlunit.WebConnection'))
43
-
44
- page = client.getPage('http://localhost:3000/')
45
- puts page.asXml
46
- puts page.getTitleText
47
-
48
- # mock = Connection::Mock.new
49
- # mock.mock :get, 'http://localhost:3000/', page
50
- # mock.mock :get, 'http://localhost:3000/ajax', 'post ajax call!', 'Content-Type' => 'application/javascript'
51
- #
52
- # browser = Browser::HtmlUnit.new(mock)
53
- # # client.setWebConnection(Rjb::bind(connection, 'com.gargoylesoftware.htmlunit.WebConnection'))
54
- #
55
- # response = browser.get('http://localhost:3000/').last
56
- # puts browser.page.asXml
57
-
@@ -1,21 +0,0 @@
1
- require 'rubygems'
2
- require 'rjb'
3
-
4
- class_path = Dir[File.expand_path(File.dirname(__FILE__) + '/../../lib/htmlunit') + '/*.jar'].join(':')
5
- Rjb::load(class_path)
6
-
7
-
8
- # klass = Rjb::import('java.lang.String')
9
- Arrays = Rjb::import('java.util.Arrays')
10
- WebResponseData = Rjb::import('com.gargoylesoftware.htmlunit.WebResponseData')
11
-
12
- # WebResponseData.getConstructors.each do |method|
13
- # params = method.getParameterTypes.map { |type| type.getName }.join(', ')
14
- # puts "#{method.getName}(#{params})"
15
- # end
16
-
17
- headers = Arrays.asList([])
18
-
19
- # com.gargoylesoftware.htmlunit.WebResponseData([B, int, java.lang.String, java.util.List)
20
- signature = '[B;I;Ljava.lang.String;Ljava.util.List;'
21
- WebResponseData.new_with_sig(signature, 'foo'.split(/./), 1, "", headers)
@@ -1,48 +0,0 @@
1
- require 'rubygems'
2
- require 'webrat'
3
-
4
-
5
- class Browser
6
- include Webrat::Locators
7
-
8
- class Cache
9
- def elements
10
- @elements ||= {}
11
- end
12
-
13
- def clear
14
- @elements.clear
15
- end
16
- end
17
-
18
- def initialize
19
- @cache = Cache.new
20
- end
21
-
22
- def find_link(text_or_title_or_id)
23
- element = LinkLocator.new(@cache, dom, text_or_title_or_id).locate!
24
- end
25
-
26
- def dom
27
- Webrat::XML.xml_document(html)
28
- end
29
-
30
- def html
31
- <<-html
32
- <html>
33
- <head>
34
- </head>
35
- <body>
36
- <a href="/">Home</a>
37
- <p>Welcome!</p>
38
- <p>Click here to <a href="/foo">foo</a>.</p>
39
- </body>
40
- </html>
41
- html
42
- end
43
- end
44
-
45
- browser = Browser.new
46
- # p Webrat::XML.xpath_to(browser.find_link_element('foo'))
47
- p browser.find_link('foo').path
48
-
@@ -1,61 +0,0 @@
1
- require 'rubygems'
2
- require 'rjb'
3
-
4
- class_path = Dir[File.expand_path(File.dirname(__FILE__) + '/../../lib/htmlunit') + '/*.jar'].join(':')
5
-
6
- Rjb::load(class_path)
7
-
8
- Url = Rjb::import('java.net.URL')
9
- WebClient = Rjb::import('com.gargoylesoftware.htmlunit.WebClient')
10
- HtmlUnitMockWebConnection = Rjb::import('com.gargoylesoftware.htmlunit.MockWebConnection')
11
-
12
- class MockConnection
13
- attr_reader :connection
14
-
15
- def initialize
16
- @connection = HtmlUnitMockWebConnection.new
17
- end
18
-
19
- def method_missing(method, *args)
20
- p [method, args.first.toString]
21
- @connection.send(method, *args)
22
- end
23
- end
24
-
25
- connection = MockConnection.new
26
- # connection = HtmlUnitMockWebConnection.new
27
-
28
- content = <<-html
29
- <html>
30
- <head>
31
- <script>
32
- document.title = 'pre ajax call';
33
- function some_ajax(url) {
34
- xhr = new XMLHttpRequest();
35
- xhr.open("GET", url, true);
36
- xhr.setRequestHeader("Accept", "application/json, text/javascript, */*");
37
- xhr.onreadystatechange = function() {
38
- document.title = document.title + ' ' + xhr.readyState
39
- if(xhr.readyState == 4) document.title = xhr.responseText
40
- }
41
- xhr.send(null);
42
- }
43
- some_ajax('/ajax/1');
44
- </script>
45
- </head>
46
- </html>
47
- html
48
- url = Url.new('http://localhost:3000/foo')
49
- connection.setResponse(url, content, 'text/html')
50
-
51
- content = 'document.title = "FOO";'
52
- url = Url.new('http://localhost:3000/ajax/1')
53
- connection.setResponse(url, content, 'application/javascript')
54
-
55
- client = WebClient.new
56
- client.setCssEnabled(true)
57
- client.setJavaScriptEnabled(true)
58
- client.setWebConnection(Rjb::bind(connection, 'com.gargoylesoftware.htmlunit.WebConnection'))
59
- # client.setWebConnection(connection)
60
- page = client.getPage('http://localhost:3000/foo')
61
- # puts page.asXml
data/test/process_test.rb DELETED
@@ -1,55 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class ProcessTest < Test::Unit::TestCase
4
- include Steam
5
-
6
- def setup
7
- delete_pid
8
- end
9
-
10
- def teardown
11
- delete_pid
12
- end
13
-
14
- def write_pid(pid)
15
- File.open('/tmp/steam.pid', 'w') { |f| f.write(pid) }
16
- end
17
-
18
- def delete_pid
19
- File.delete('/tmp/steam.pid') rescue Errno::ENOENT
20
- end
21
-
22
- test "new instance recalls an existing pid" do
23
- write_pid(::Process.pid)
24
- assert_equal ::Process.pid, Process.new.pid
25
- end
26
-
27
- test "pid? returns true if pid was recalled" do
28
- write_pid(::Process.pid)
29
- assert_equal true, Process.new.pid?
30
- end
31
-
32
- test "pid? returns false if pid could not be recalled" do
33
- assert_equal false, Process.new.pid?
34
- end
35
-
36
- test "running? returns true if pid refers to an existing process" do
37
- write_pid(::Process.pid)
38
- assert_equal true, Process.new.running?
39
- end
40
-
41
- test "running? returns false if pid does not refer to an existing process" do
42
- write_pid(1073741823)
43
- assert_equal false, Process.new.running?
44
- end
45
-
46
- # # WTF the child process actually writes to /tmp/out.txt but File.read('/tmp/out.txt')
47
- # # returns an empty string
48
- # test "fork forks the process, reopens given streams and yields the given block" do
49
- # File.delete('/tmp/out.txt') rescue Errno::ENOENT
50
- # io = File.open('/tmp/out.txt', 'w+')
51
- # io.sync = true
52
- # Process.new.fork(:out => io) { puts 'foo' }
53
- # assert_equal 'foo', File.open('/tmp/out.txt', 'r') { |f| f.read }
54
- # end
55
- end
data/test/session_test.rb DELETED
@@ -1,40 +0,0 @@
1
- require File.expand_path('../test_helper', __FILE__)
2
-
3
- class SessionTest < Test::Unit::TestCase
4
- include Steam
5
-
6
- def setup
7
- @browser = Browser::HtmlUnit.new(Connection::Mock.new)
8
- @session = Session.new(@browser)
9
-
10
- perform(:get, 'http://localhost:3000/', '<div id="foo"><div id="bar"><a id="buz" href="">bar!</a></div></div>')
11
- end
12
-
13
- test 'session responds to browser methods' do
14
- assert @session.respond_to?(:response)
15
- end
16
-
17
- test 'assert_contain' do
18
- @session.assert_contain(@session.response.body, 'bar!')
19
- end
20
-
21
- test 'assert_not_contain' do
22
- @session.assert_not_contain(@session.response.body, 'bar!!')
23
- end
24
-
25
- test 'assert_have_tag' do
26
- @session.assert_have_tag(@session.response.body, :a, 'bar!', :id => 'buz')
27
- end
28
-
29
- test 'assert_have_no_tag' do
30
- @session.assert_have_no_tag(@session.response.body, :a, 'bar!', :class => 'buz')
31
- end
32
-
33
- test 'assert_have_xpath' do
34
- @session.assert_have_xpath(@session.response.body, '//div/a[@id="buz"]')
35
- end
36
-
37
- test 'assert_have_no_xpath' do
38
- @session.assert_have_no_xpath(@session.response.body, '//div/a[@class="buz"]')
39
- end
40
- end
data/test/test_helper.rb DELETED
@@ -1,80 +0,0 @@
1
- require 'test/unit'
2
- require 'mocha'
3
- require 'erb'
4
-
5
- TEST_ROOT = File.expand_path("../", __FILE__)
6
-
7
- $: << File.expand_path("../lib", TEST_ROOT)
8
- $: << TEST_ROOT
9
-
10
- FIXTURES_PATH = File.expand_path("../fixtures", __FILE__)
11
-
12
- require 'steam'
13
-
14
- # Steam::Java.import('com.gargoylesoftware.htmlunit.StringWebResponse')
15
- # Steam::Java.import('com.gargoylesoftware.htmlunit.WebClient')
16
- # Steam::Java.import('com.gargoylesoftware.htmlunit.TopLevelWindow')
17
- # Steam::Java.import('com.gargoylesoftware.htmlunit.DefaultPageCreator')
18
-
19
- module TestMethod
20
- def self.included(base)
21
- base.class_eval do
22
- def test(name, &block)
23
- test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
24
- defined = instance_method(test_name) rescue false
25
- raise "#{test_name} is already defined in #{self}" if defined
26
- if block_given?
27
- define_method(test_name, &block)
28
- else
29
- define_method(test_name) do
30
- flunk "No implementation provided for #{name}"
31
- end
32
- end
33
- end
34
- end
35
- end
36
- end
37
-
38
- class Module
39
- include TestMethod
40
- end
41
-
42
- class Test::Unit::TestCase
43
- include TestMethod
44
-
45
- def mock(method, url, response)
46
- connection = @browser.connection
47
- connection = connection.apps.last if connection.is_a?(Rack::Cascade)
48
- connection.mock(method, url, response)
49
- end
50
-
51
- def perform(method, url, response)
52
- mock(method, url, response)
53
- @status, @headers, @response = @browser.call(Steam::Request.env_for(url))
54
- end
55
-
56
- def assert_response_contains(text, options = {})
57
- tag_name = options[:in] || 'body'
58
- response = yield
59
- assert_equal 200, response.status
60
- assert_match %r(<#{tag_name}>\s*#{text}\s*<\/#{tag_name}>), response.body
61
- end
62
-
63
- def assert_passes
64
- begin
65
- yield
66
- rescue Test::Unit::AssertionFailedError => e
67
- ensure
68
- assert_nil e
69
- end
70
- end
71
-
72
- def assert_fails
73
- begin
74
- yield
75
- rescue Test::Unit::AssertionFailedError => e
76
- ensure
77
- assert_not_nil e
78
- end
79
- end
80
- end