capy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capy.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 jugyo
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,39 @@
1
+ # Capy
2
+
3
+ The capy command to run the script written in Capybara DSL.
4
+
5
+ ## Installation
6
+
7
+ $ gem install capy
8
+
9
+ ## Usage
10
+
11
+ ### Capy Shell
12
+
13
+ $ capy
14
+
15
+ ### Running Script
16
+
17
+ Write script
18
+
19
+ # example.capy
20
+
21
+ visit 'http://www.wikipedia.org/'
22
+ fill_in 'search', :with => 'ruby'
23
+ click_on ' → '
24
+
25
+ and
26
+
27
+ $ capy example.capy
28
+
29
+ Run as nonstop mode:
30
+
31
+ $ capy -n example.capy
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/capy ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'capy'
3
+ args = ARGV.dup
4
+ ARGV.clear
5
+ Capy.run(args)
data/capy.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capy/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["jugyo"]
6
+ gem.email = ["jugyo.org@gmail.com"]
7
+ gem.description = %q{Capybara Script Runner}
8
+ gem.summary = %q{The capy command to run the script written in Capybara DSL.}
9
+ gem.homepage = "https://github.com/jugyo"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capy"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capy::VERSION
17
+
18
+ gem.add_runtime_dependency 'slop', '~>3.1'
19
+ gem.add_runtime_dependency 'capybara'
20
+ gem.add_runtime_dependency 'colored'
21
+ end
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env capy
2
+
3
+ visit 'http://google.com/'
4
+ fill_in 'q', :with => 'ruby'
5
+ page.evaluate_script("document.forms[0].submit()")
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env capy
2
+
3
+ visit 'http://www.wikipedia.org/'
4
+ fill_in 'search', :with => 'ruby'
5
+ click_on ' → '
data/lib/capy.rb ADDED
@@ -0,0 +1,77 @@
1
+ require "capy/version"
2
+ require "slop"
3
+ require "colored"
4
+ require 'capybara/dsl'
5
+
6
+ module Capy
7
+ class << self
8
+ attr_reader :opts
9
+
10
+ def run(args)
11
+ @opts = Slop.parse!(args, :help => true) do
12
+ banner "capy foo.capy\n"
13
+ on :n, :nonstop
14
+ end
15
+ exit if opts.help?
16
+
17
+ Capybara.register_driver(:selenium) { |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) }
18
+ Capybara.current_driver = :selenium
19
+
20
+ if args.empty?
21
+ start_shell
22
+ else
23
+ args.each do |script_file|
24
+ abort "No such file: #{script_file}".red unless File.exists?(script_file)
25
+ puts "Running: #{script_file} ..."
26
+ eval_script script_file
27
+ end
28
+ end
29
+ end
30
+
31
+ def start_shell
32
+ require 'readline'
33
+ Readline.completion_proc = lambda do |text|
34
+ (Capybara::DSL.instance_methods + [:exit]).grep /^#{Regexp.quote(text.strip)}/
35
+ end
36
+ evaluater = Evaluater.new
37
+ puts 'Type `exit` to exit'
38
+ while buf = Readline.readline('> ', true)
39
+ case buf.strip
40
+ when 'exit'
41
+ exit
42
+ else
43
+ begin
44
+ result = evaluater.instance_eval(buf)
45
+ puts "=> #{result.inspect}".cyan
46
+ rescue => e
47
+ error e
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ def eval_script(script_file)
54
+ Evaluater.new.instance_eval(<<-SCRIPT, script_file, 1)
55
+ #{File.read(script_file)}
56
+ SCRIPT
57
+ rescue => e
58
+ error e
59
+ ensure
60
+ unless opts.nonstop?
61
+ print 'Press Enter to exit: '.bold
62
+ gets
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def error(e)
69
+ puts "#{e.backtrace[0]} #{e}".red
70
+ puts "\t#{e.backtrace[1..-1].join("\n\t")}".red
71
+ end
72
+ end
73
+
74
+ class Evaluater
75
+ include Capybara::DSL
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module Capy
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - jugyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: slop
16
+ requirement: &70155069650840 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70155069650840
25
+ - !ruby/object:Gem::Dependency
26
+ name: capybara
27
+ requirement: &70155069650400 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70155069650400
36
+ - !ruby/object:Gem::Dependency
37
+ name: colored
38
+ requirement: &70155069649900 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70155069649900
47
+ description: Capybara Script Runner
48
+ email:
49
+ - jugyo.org@gmail.com
50
+ executables:
51
+ - capy
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - bin/capy
60
+ - capy.gemspec
61
+ - examples/google_search.capy
62
+ - examples/wikipedia_search.capy
63
+ - lib/capy.rb
64
+ - lib/capy/version.rb
65
+ homepage: https://github.com/jugyo
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: The capy command to run the script written in Capybara DSL.
89
+ test_files: []