mike 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/.gitignore +20 -0
  2. data/.rspec +1 -0
  3. data/Isolate +8 -0
  4. data/README.md +22 -0
  5. data/Rakefile +41 -0
  6. data/lib/mike.rb +64 -0
  7. data/mike.gemspec +21 -0
  8. data/spec/spec_helper.rb +14 -0
  9. metadata +134 -0
@@ -0,0 +1,20 @@
1
+ *.so
2
+ *.o
3
+ *.log
4
+ Makefile
5
+ \#.*
6
+ .\#.*
7
+ *.a
8
+ *.exe
9
+ build
10
+ pkg
11
+ tmp
12
+ eproject.cfg
13
+ .eproject
14
+ *.bundle
15
+ .svn
16
+ .DS_Store
17
+ *.gem
18
+ *.rbc
19
+
20
+ examples
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/Isolate ADDED
@@ -0,0 +1,8 @@
1
+ # -*- ruby -*-
2
+
3
+ gem "mustang", "~> 0.2"
4
+
5
+ env :development, :test do
6
+ gem "rspec", "~> 2.5"
7
+ gem "mocha", ">= 0.9"
8
+ end
@@ -0,0 +1,22 @@
1
+ NOTE: this code is under development...
2
+
3
+ # Mike - The Headless Browser
4
+
5
+ Mike is a headless <del>chicken</del> web browser for testing purposes powered by awesome V8 JavaScript
6
+ engine (via [Mustang gem](http://github.com/nu7hatch/mustang)).
7
+
8
+ This lib is named Mike, in memory of the [brave headless chicken](http://en.wikipedia.org/wiki/Mike_the_Headless_Chicken) :)
9
+
10
+ ## Note on Patches/Pull Requests
11
+
12
+ * Fork the project.
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a
15
+ future version unintentionally.
16
+ * Commit, do not mess with rakefile, version, or history.
17
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
18
+ * Send me a pull request. Bonus points for topic branches.
19
+
20
+ ## Copyright
21
+
22
+ Copyright (c) 2010 by nu7. See LICENSE for details.
@@ -0,0 +1,41 @@
1
+ # -*- ruby -*-
2
+
3
+ begin
4
+ require 'isolate/now'
5
+ rescue LoadError
6
+ STDERR.puts "Run `gem install isolate` to install 'isolate'."
7
+ end
8
+
9
+ begin
10
+ require 'rspec/core/rake_task'
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = ENV['RSPEC_OPTS']
13
+ end
14
+ rescue LoadError
15
+ task :spec do
16
+ abort 'Run `gem install rspec` to install RSpec'
17
+ end
18
+ end
19
+
20
+ task :default => :spec
21
+
22
+ begin
23
+ require 'metric_fu'
24
+ rescue LoadError
25
+ end
26
+
27
+ require 'rake/rdoctask'
28
+ Rake::RDocTask.new do |rdoc|
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = "Mustang - V8 for ruby"
31
+ rdoc.rdoc_files.include('README*')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
34
+
35
+ desc "Opens console with loaded mike's env."
36
+ task :console do
37
+ require 'mike'
38
+ require 'irb'
39
+ ARGV.clear
40
+ IRB.start
41
+ end
@@ -0,0 +1,64 @@
1
+ require 'mustang'
2
+ require 'hpricot'
3
+
4
+ module Mike
5
+ module Env
6
+ def print(*args)
7
+ puts(*args)
8
+ end
9
+ end # Env
10
+
11
+ class Document
12
+ attr_reader :js
13
+ attr_reader :url
14
+ attr_reader :dom
15
+ attr_reader :html
16
+
17
+ def initialize(url)
18
+ @url = url
19
+ @html = load_url(@url)
20
+ @dom = Hpricot(@html)
21
+ @js = Mustang::Context.new
22
+
23
+ prepare_context
24
+ process_scripts
25
+ end
26
+
27
+ def scripts
28
+ (@dom/"//script")
29
+ end
30
+
31
+ private
32
+
33
+ def load_url(url)
34
+ File.read(url) # just for the test
35
+ end
36
+
37
+ def prepare_context
38
+ Env.instance_methods(false).each { |meth|
39
+ @js.set :print, Env.instance_method(meth)
40
+ }
41
+ end
42
+
43
+ def process_scripts
44
+ scripts.each { |script|
45
+ unless script.attributes["src"].empty?
46
+ @js.load(script.attributes["src"])
47
+ else
48
+ @js.eval(script.html)
49
+ end
50
+ }
51
+ end
52
+ end # Document
53
+
54
+ class Browser
55
+ def initialize
56
+ end
57
+
58
+ def open(url)
59
+ doc = Document.new(url)
60
+ yield doc if block_given?
61
+ doc
62
+ end
63
+ end # Browser
64
+ end # Mike
@@ -0,0 +1,21 @@
1
+ # -*- ruby -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "mike"
5
+ s.summary = "Truelly headless browser"
6
+ s.version = "0.0.1"
7
+ s.authors = ["Chris Kowalik", "Bruno Aguirre", "Cubox"]
8
+ s.description = "Headless browser for testing purposes powered by V8 JavaScript engine (via Mustang gem)"
9
+ s.homepage = "http://github.com/nu7hatch/mike"
10
+ s.email = "chris@nu7hat.ch"
11
+ s.license = "MIT"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files spec`.split("\n")
15
+
16
+ s.add_runtime_dependency "mustang", "~> 0.2"
17
+ s.add_runtime_dependency "hpricot"
18
+
19
+ s.add_development_dependency "rspec", "~> 2.0"
20
+ s.add_development_dependency "mocha", "~> 0.9"
21
+ end
@@ -0,0 +1,14 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+
3
+ require 'rspec'
4
+ require 'mocha'
5
+ require 'mike'
6
+
7
+ RSpec.configure do |config|
8
+ config.mock_with :mocha
9
+ end
10
+
11
+ def debug
12
+ require 'ruby-debug'
13
+ debugger
14
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mike
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Chris Kowalik
14
+ - Bruno Aguirre
15
+ - Cubox
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2011-04-13 00:00:00 -03:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: mustang
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ hash: 15
32
+ segments:
33
+ - 0
34
+ - 2
35
+ version: "0.2"
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: hpricot
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 2
63
+ - 0
64
+ version: "2.0"
65
+ type: :development
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ hash: 25
76
+ segments:
77
+ - 0
78
+ - 9
79
+ version: "0.9"
80
+ type: :development
81
+ version_requirements: *id004
82
+ description: Headless browser for testing purposes powered by V8 JavaScript engine (via Mustang gem)
83
+ email: chris@nu7hat.ch
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files: []
89
+
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Isolate
94
+ - README.md
95
+ - Rakefile
96
+ - lib/mike.rb
97
+ - mike.gemspec
98
+ - spec/spec_helper.rb
99
+ has_rdoc: true
100
+ homepage: http://github.com/nu7hatch/mike
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ hash: 3
114
+ segments:
115
+ - 0
116
+ version: "0"
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ hash: 3
123
+ segments:
124
+ - 0
125
+ version: "0"
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.7
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: Truelly headless browser
133
+ test_files:
134
+ - spec/spec_helper.rb