capy 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/capy.rb +32 -12
  2. data/lib/capy/version.rb +1 -1
  3. metadata +75 -45
@@ -1,3 +1,4 @@
1
+ require 'readline'
1
2
  require "capy/version"
2
3
  require "slop"
3
4
  require "colored"
@@ -9,12 +10,15 @@ module Capy
9
10
 
10
11
  def run(args)
11
12
  @opts = Slop.parse!(args, :help => true) do
12
- banner "capy foo.capy\n"
13
+ banner "capy [script.capy]\n"
14
+ on :b, :browser=, 'chrome, firefox', :default => 'chrome'
13
15
  on :n, :nonstop
14
16
  end
15
17
  exit if opts.help?
16
18
 
17
- Capybara.register_driver(:selenium) { |app| Capybara::Selenium::Driver.new(app, :browser => :chrome) }
19
+ Capybara.register_driver :selenium do |app|
20
+ Capybara::Selenium::Driver.new(app, :browser => opts[:browser].to_sym)
21
+ end
18
22
  Capybara.current_driver = :selenium
19
23
 
20
24
  if args.empty?
@@ -28,16 +32,34 @@ module Capy
28
32
  end
29
33
  end
30
34
 
31
- def start_shell
32
- require 'readline'
35
+ def start_shell(evaluater = Evaluater.new)
36
+ exit_commands = %w(exit quit)
37
+
33
38
  Readline.completion_proc = lambda do |text|
34
- (Capybara::DSL.instance_methods + [:exit]).grep /^#{Regexp.quote(text.strip)}/
39
+ (Capybara::DSL.instance_methods + exit_commands).grep(/^#{Regexp.quote(text.strip)}/)
35
40
  end
36
- evaluater = Evaluater.new
41
+
42
+ history_file = File.expand_path('~/.capy_history')
43
+ if File.exists?(history_file)
44
+ File.read(history_file, :encoding => "BINARY").
45
+ encode!(:invalid => :replace, :undef => :replace).
46
+ split(/\n/).
47
+ each { |line| Readline::HISTORY << line }
48
+ end
49
+
37
50
  puts 'Type `exit` to exit'
51
+
38
52
  while buf = Readline.readline('> ', true)
53
+ unless Readline::HISTORY.count == 1
54
+ Readline::HISTORY.pop if buf.empty? || Readline::HISTORY[-1] == Readline::HISTORY[-2]
55
+ end
56
+
39
57
  case buf.strip
40
- when 'exit'
58
+ when *exit_commands
59
+ File.open(history_file, 'w') do |file|
60
+ lines = Readline::HISTORY.to_a[([Readline::HISTORY.size - 1000, 0].max)..-1]
61
+ file.print(lines.join("\n"))
62
+ end
41
63
  exit
42
64
  else
43
65
  begin
@@ -51,15 +73,13 @@ module Capy
51
73
  end
52
74
 
53
75
  def eval_script(script_file)
54
- Evaluater.new.instance_eval(<<-SCRIPT, script_file, 1)
55
- #{File.read(script_file)}
56
- SCRIPT
76
+ evaluater = Evaluater.new
77
+ evaluater.instance_eval(File.read(script_file), script_file, 1)
57
78
  rescue => e
58
79
  error e
59
80
  ensure
60
81
  unless opts.nonstop?
61
- print 'Press Enter to exit: '.bold
62
- gets
82
+ start_shell(evaluater)
63
83
  end
64
84
  end
65
85
 
@@ -1,3 +1,3 @@
1
1
  module Capy
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,57 +1,76 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: capy
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - jugyo
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-04-23 00:00:00.000000000Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-04-24 00:00:00 +09:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
15
22
  name: slop
16
- requirement: &70155069650840 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
17
25
  none: false
18
- requirements:
26
+ requirements:
19
27
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.1'
28
+ - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 3
32
+ - 1
33
+ version: "3.1"
22
34
  type: :runtime
23
- prerelease: false
24
- version_requirements: *70155069650840
25
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
26
37
  name: capybara
27
- requirement: &70155069650400 !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
28
40
  none: false
29
- requirements:
30
- - - ! '>='
31
- - !ruby/object:Gem::Version
32
- version: '0'
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
33
48
  type: :runtime
34
- prerelease: false
35
- version_requirements: *70155069650400
36
- - !ruby/object:Gem::Dependency
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
37
51
  name: colored
38
- requirement: &70155069649900 !ruby/object:Gem::Requirement
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
39
54
  none: false
40
- requirements:
41
- - - ! '>='
42
- - !ruby/object:Gem::Version
43
- version: '0'
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
44
62
  type: :runtime
45
- prerelease: false
46
- version_requirements: *70155069649900
63
+ version_requirements: *id003
47
64
  description: Capybara Script Runner
48
- email:
65
+ email:
49
66
  - jugyo.org@gmail.com
50
- executables:
67
+ executables:
51
68
  - capy
52
69
  extensions: []
70
+
53
71
  extra_rdoc_files: []
54
- files:
72
+
73
+ files:
55
74
  - Gemfile
56
75
  - LICENSE
57
76
  - README.md
@@ -62,28 +81,39 @@ files:
62
81
  - examples/wikipedia_search.capy
63
82
  - lib/capy.rb
64
83
  - lib/capy/version.rb
84
+ has_rdoc: true
65
85
  homepage: https://github.com/jugyo
66
86
  licenses: []
87
+
67
88
  post_install_message:
68
89
  rdoc_options: []
69
- require_paths:
90
+
91
+ require_paths:
70
92
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
93
+ required_ruby_version: !ruby/object:Gem::Requirement
72
94
  none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
103
  none: false
79
- requirements:
80
- - - ! '>='
81
- - !ruby/object:Gem::Version
82
- version: '0'
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
83
111
  requirements: []
112
+
84
113
  rubyforge_project:
85
- rubygems_version: 1.8.10
114
+ rubygems_version: 1.3.7
86
115
  signing_key:
87
116
  specification_version: 3
88
117
  summary: The capy command to run the script written in Capybara DSL.
89
118
  test_files: []
119
+