superbara 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9398c3450c5aac178102ba61fd6908bfa1cc9b1e514090af69450850c9d3baa0
4
- data.tar.gz: e5b9fde8a63e5fac2ae2400ae52cfcb88da49500af4bf53827794111a8438dc5
3
+ metadata.gz: ffe6293f27192cca303e3024bd37faeeae3467f264f1052cca556823fd5a275d
4
+ data.tar.gz: 7df3dde796cb590b7b3a65057a9603bf6d5a61d364dec00d1e1f246252e6054c
5
5
  SHA512:
6
- metadata.gz: dfbce06e7c6564c011375a3d48b7be585cb659edd3b6928bcdc8e463694b51b6728c301ea95462ac2e30f4bf6701228ffd0ef7c6beedfbb28ecbe49ec4cc4343
7
- data.tar.gz: 9b75c0daa7d629f422aa91a53272993822bdef0d2e47f9f62700687c2fd77debee06139147d484ded93268dbac7ab6fad9b8fc9ba7b2bd913c268352ecf84346
6
+ metadata.gz: 16f2b79e5c269cccec533ea3df29ef9e0b0468efb6ce52732829e5e36ee69ae9810c0157fb84564d09e33d1ce70771f0a1cd4860144c50ef49fc2c759658686e
7
+ data.tar.gz: 31fb3c8a6210cdec887145ea4ce64f88825e8d0d8d106c49fd4816c13f3c0a01d3b25c18aa4ee02b5ff51b7863e07335e7e8534c9503e8a9cfea66ee16b0e9d1
data/Dockerfile CHANGED
@@ -3,4 +3,6 @@ ARG version
3
3
  COPY superbara-${version}.gem /tmp
4
4
  RUN gem install /tmp/superbara-${version}.gem && rm /tmp/superbara-${version}.gem
5
5
 
6
- ENTRYPOINT ["/usr/local/bundle/bin/superbara", "run", "/e2e"]
6
+ WORKDIR /tests
7
+ CMD ["all"]
8
+ ENTRYPOINT ["/usr/local/bundle/bin/superbara", "run"]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbara (0.5.1)
4
+ superbara (0.6.0)
5
5
  binding_of_caller (~> 0.8, >= 0.8.0)
6
6
  capybara (~> 3.1, >= 3.1.0)
7
7
  chromedriver-helper (~> 1.2.0, >= 1.2.0)
@@ -44,6 +44,7 @@ GEM
44
44
  i18n (1.0.1)
45
45
  concurrent-ruby (~> 1.0)
46
46
  io-like (0.3.0)
47
+ kommando (0.1.2)
47
48
  method_source (0.9.0)
48
49
  mini_mime (1.0.0)
49
50
  mini_portile2 (2.3.0)
@@ -94,6 +95,7 @@ PLATFORMS
94
95
 
95
96
  DEPENDENCIES
96
97
  bundler (~> 1.15, >= 1.15.0)
98
+ kommando (~> 0.1, >= 0.1.2)
97
99
  rake (~> 10.0, >= 10.0.0)
98
100
  rspec (~> 3.7, >= 3.7.0)
99
101
  superbara!
data/README.md CHANGED
@@ -22,7 +22,7 @@ name_field.type "Sarah", :enter
22
22
  if has_text? "Welcome, Sarah"
23
23
  run "logout"
24
24
  else
25
- fail "no greeting visible"
25
+ assert "no greeting visible"
26
26
  end
27
27
  ```
28
28
 
data/Rakefile CHANGED
@@ -3,4 +3,16 @@ require "rspec/core/rake_task"
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task :default => [:spec, :superbara]
7
+
8
+ task :superbara do
9
+ require 'kommando'
10
+
11
+ k = Kommando.new "bin/tests", {
12
+ output: true
13
+ }
14
+
15
+ k.run
16
+
17
+ raise "not clean" unless k.code == 0
18
+ end
data/bin/release CHANGED
@@ -3,7 +3,6 @@ set -e
3
3
  version=$(exe/superbara version)
4
4
 
5
5
  rake
6
- SUPERBARA_FRONTEND=noninteractive exe/superbara run e2e
7
6
 
8
7
  gem build superbara.gemspec
9
8
  KUNG_ENV=build VERSION=$version kung build
data/bin/tests ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env sh
2
+ set -e
3
+ tests="all minimal"
4
+
5
+ for test in $tests; do
6
+ set +e
7
+ exe/superbara run tests/$test
8
+ exit_status=$?
9
+ set -e
10
+
11
+ if [ "$exit_status" != 0 ]; then
12
+ echo "err!"
13
+ exit 1
14
+ fi
15
+ done
16
+
17
+ set +e
18
+ exe/superbara run tests/fail
19
+ exit_status=$?
20
+ set -e
21
+
22
+ if [ "$exit_status" != 1 ]; then
23
+ echo "err!"
24
+ exit 1
25
+ fi
26
+
27
+ echo "success!"
@@ -7,7 +7,7 @@ services:
7
7
  - SUPERBARA_FRONTEND=noninteractive
8
8
  - CHROME_URL=http://chrome:4444/wd/hub
9
9
  volumes:
10
- - ./e2e:/e2e
10
+ - ./tests:/tests
11
11
  depends_on:
12
12
  - chrome
13
13
  chrome:
data/lib/pry_monkey.rb CHANGED
@@ -71,8 +71,8 @@ Pry.commands.alias_command 'n', 'next'
71
71
  Pry.commands.alias_command 'h', 'help'
72
72
 
73
73
  Pry::Commands.command /^e$/, "edit" do
74
- puts "Opening #{Superbara.project_path} ..."
75
- `superbara edit #{Superbara.project_path}`
74
+ output = `superbara edit #{Superbara.project_path}`
75
+ puts output
76
76
  end
77
77
 
78
78
  Pry::Commands.command /^help$/, "help" do
data/lib/superbara/cli.rb CHANGED
@@ -5,6 +5,26 @@ module Superbara; module CLI
5
5
  case main_command
6
6
  when "version"
7
7
  puts Superbara::VERSION
8
+ exit 0
9
+ when "edit"
10
+ editor_cmd = if ENV["SUPERBARA_EDITOR"]
11
+ ENV["SUPERBARA_EDITOR"]
12
+ elsif ENV["EDITOR"]
13
+ ENV["EDITOR"]
14
+ else
15
+ 'open'
16
+ end
17
+
18
+ dir_or_file = ARGV[1]
19
+
20
+ puts "Opening #{dir_or_file} with #{editor_cmd} .."
21
+
22
+ if editor_cmd == "nano"
23
+ exec "#{editor_cmd} #{dir_or_file}"
24
+ else
25
+ `#{editor_cmd} #{dir_or_file}`
26
+ end
27
+
8
28
  exit 0
9
29
  when "web", "shell"
10
30
  #
@@ -20,18 +40,24 @@ module Superbara; module CLI
20
40
  exit 1
21
41
  end
22
42
 
23
- contents = """visit \"http://example.com\"
43
+ contents = """visit 'example.com'
24
44
 
25
45
  wait 3 do
26
- has_text? \"Example Domain\"
46
+ has_text? 'Example Domain'
27
47
  end
28
- click \"h1\"
48
+
29
49
  think 1..3
30
- click \"a\"
50
+
51
+ click 'a'
31
52
  scroll 50
32
53
  """
33
54
  Dir.mkdir project_name
34
55
  File.write File.join(project_name, "main.rb"), contents
56
+
57
+ puts "Created directory #{project_name} with main.rb"
58
+ puts "Start testing with:"
59
+ puts ""
60
+ puts " superbara start #{project_name}"
35
61
  exit 0
36
62
  else
37
63
  unless ARGV[1]
@@ -48,13 +74,26 @@ scroll 50
48
74
  """
49
75
  exit 1
50
76
  end
77
+ end
51
78
 
52
- project_path_expanded = File.expand_path(ARGV[1])
79
+ case main_command
80
+ when "start", "run"
81
+ project_path_or_file_expanded = File.expand_path(ARGV[1])
53
82
 
54
- Superbara.project_path = if Dir.exists? project_path_expanded
55
- project_path_expanded
83
+ Superbara.project_path, project_entrypoint = if Dir.exists? project_path_or_file_expanded
84
+ unless File.exist? File.join(project_path_or_file_expanded, "main.rb")
85
+ puts "No main.rb found in #{project_path_or_file_expanded}"
86
+ puts "Alternatively you can also specify the file name."
87
+ exit 1
88
+ end
89
+ [project_path_or_file_expanded, "main.rb"]
90
+ elsif File.exists? project_path_or_file_expanded
91
+ [
92
+ File.dirname(project_path_or_file_expanded),
93
+ File.basename(project_path_or_file_expanded)
94
+ ]
56
95
  else
57
- puts "#{project_path_expanded} is not a directory"
96
+ puts "#{project_path_or_file_expanded} is not a directory or a file"
58
97
  exit 1
59
98
  end
60
99
  end
@@ -68,7 +107,7 @@ scroll 50
68
107
  begin
69
108
  case main_command
70
109
  when "web"
71
- webapp = Superbara::Web.new
110
+ webapp = Superbara::Web.new port: (ENV['SUPERBARA_WEB_PORT'] || 4567)
72
111
  webapp.run!
73
112
  exit 0
74
113
  when "shell"
@@ -90,11 +129,16 @@ scroll 50
90
129
  puts ""
91
130
  puts "t action".colorize(:light_black)
92
131
  Superbara.start!
93
- Superbara.visual_disable!
94
- Superbara.current_context.__superbara_eval "visit 'about:blank'"
95
- Superbara.visual_enable!
132
+ Superbara.visual_disabled do
133
+ Superbara.current_context.__superbara_eval "visit 'about:blank'"
134
+ end
96
135
 
97
- Superbara.current_context.__superbara_load(File.join(Superbara.project_path, "main.rb"))
136
+ case main_command
137
+ when "start"
138
+ Superbara.visual_enable!
139
+ end
140
+
141
+ Superbara.current_context.__superbara_load(File.join(Superbara.project_path, project_entrypoint))
98
142
 
99
143
  puts """
100
144
  🏁 🏁 🏁 done."""
@@ -126,7 +170,12 @@ scroll 50
126
170
  in #{offending_file_path}:#{offending_line}
127
171
  #{offending_line}: #{offending_code}""".colorize(:light_black)
128
172
 
129
- Superbara.current_context.__superbara_debug
173
+ case main_command
174
+ when "start"
175
+ Superbara.current_context.__superbara_debug
176
+ else
177
+ exit 1
178
+ end
130
179
  end
131
180
  end
132
181
  end
data/lib/superbara/dsl.rb CHANGED
@@ -3,7 +3,15 @@ module Superbara; module DSL
3
3
  #"Superbara::DSL included in #{includer.inspect}"
4
4
  end
5
5
 
6
- def fail(message=nil)
6
+ def assert(message=nil, &block)
7
+ failed = if block
8
+ !block.call
9
+ else
10
+ true
11
+ end
12
+
13
+ return unless failed
14
+
7
15
  if message
8
16
  Superbara.output ("FAIL: ".colorize(:red) + message)
9
17
  else
@@ -73,11 +81,25 @@ return Array.from(
73
81
  @@once_runs << what
74
82
  end
75
83
  end
76
-
77
84
  Superbara.output "run #{what}"
78
85
  Superbara.toast "run #{what}" if Superbara.visual?
79
86
 
80
- Superbara.current_context.__superbara_load(File.join(Superbara.project_path, "#{what}.rb"))
87
+ what_expanded = File.expand_path(File.join(Superbara.project_path, what))
88
+ better_what = if Dir.exist? what_expanded
89
+ File.join what_expanded, "main.rb"
90
+ elsif what_expanded.end_with? ".rb"
91
+ what_expanded
92
+ else
93
+ "#{what_expanded}.rb"
94
+ end
95
+
96
+ old_project_path = Superbara.project_path
97
+ unless Superbara.project_path == File.dirname(better_what)
98
+ Superbara.project_path = File.dirname(better_what)
99
+ end
100
+
101
+ Superbara.current_context.__superbara_load(better_what)
102
+ Superbara.project_path = old_project_path
81
103
  end
82
104
 
83
105
  def visit(visit_uri_or_domain_or_path)
@@ -255,7 +277,7 @@ return Array.from(
255
277
  q - exit to shell"""
256
278
 
257
279
  debug_header_prefix = "== DEBUG "
258
- debug_header_suffix = "=" * (IO.console.winsize.last - debug_header_prefix.size)
280
+ debug_header_suffix = "=" * (IO.console.winsize.last - debug_header_prefix.size).abs
259
281
 
260
282
  if help
261
283
  puts """
@@ -1,3 +1,3 @@
1
1
  module Superbara
2
- VERSION = "0.5.1"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/superbara/web.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'sinatra/base'
2
2
 
3
3
  module Superbara; class Web
4
- def initialize(access_log: true, server_bind: '127.0.0.1')
4
+ def initialize(access_log: true, server_bind: '127.0.0.1', port: 4567)
5
5
  @webapp = Sinatra.new do
6
6
  root_path = File.join(File.dirname(__FILE__), "..", "..", "web")
7
7
 
@@ -11,6 +11,7 @@ module Superbara; class Web
11
11
 
12
12
  set :bind, server_bind
13
13
  set :root, root_path
14
+ set :port, port
14
15
 
15
16
  get '/' do
16
17
  File.read(File.join(root_path,"public", "index.html"))
data/lib/superbara.rb CHANGED
@@ -46,6 +46,25 @@ module Superbara
46
46
  return true if ENV["SUPERBARA_VISUAL"]
47
47
  end
48
48
 
49
+ def self.visual_disabled(&block)
50
+ env_was_set = if ENV["SUPERBARA_VISUAL"]
51
+ ENV.delete "SUPERBARA_VISUAL"
52
+ true
53
+ end
54
+
55
+ visual_was_set = if Superbara.visual?
56
+ self.visual_disable!
57
+ true
58
+ end
59
+
60
+ value = block.call
61
+
62
+ ENV["SUPERBARA_VISUAL"] = "true" if env_was_set
63
+ Superbara.visual_enable! if visual_was_set
64
+
65
+ value
66
+ end
67
+
49
68
  def self.visual_enable!
50
69
  @@visual = true
51
70
  end
data/superbara.gemspec CHANGED
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'bundler', '~> 1.15', '>= 1.15.0'
33
33
  spec.add_development_dependency 'rake', '~> 10.0', '>= 10.0.0'
34
34
  spec.add_development_dependency 'rspec', '~> 3.7', '>= 3.7.0'
35
+ spec.add_development_dependency 'kommando', '~> 0.1', '>= 0.1.2'
35
36
  end
data/tests/all/main.rb ADDED
@@ -0,0 +1,15 @@
1
+ run "../common", once: true
2
+
3
+ wait "3" do
4
+ has_text? "Superbara"
5
+ end
6
+
7
+ for feature_path in Dir.glob("tests/features/*.rb") do
8
+ feature_file = "../features/#{File.basename(feature_path)}"
9
+
10
+ puts """
11
+
12
+ RUNNING: #{feature_file}
13
+ """
14
+ run "../features/#{File.basename(feature_path)}"
15
+ end
@@ -0,0 +1,4 @@
1
+ run "vars"
2
+ run "webapp", once: true
3
+
4
+ visit "#{$test_host}:4567"
File without changes
File without changes
@@ -0,0 +1 @@
1
+ asdf
@@ -0,0 +1,9 @@
1
+ run "../common"
2
+
3
+ visit "example.com"
4
+
5
+ wait 5 do
6
+ has_text? "Example Domain"
7
+ end
8
+
9
+ run "../common"
@@ -0,0 +1,17 @@
1
+ run "../common"
2
+
3
+ h1 = find "h1"
4
+ assert h1.text do
5
+ h1.text == "Superbara"
6
+ end
7
+
8
+ h1_text = find "h1", text: "Superbara"
9
+ assert h1_text.text do
10
+ h1_text.text == "Superbara"
11
+ end
12
+
13
+ another = find "a", text: "Another"
14
+ assert another.text do
15
+ another.text == "Another page"
16
+ end
17
+
@@ -0,0 +1,37 @@
1
+ run "../common"
2
+
3
+ click_link "Another page"
4
+
5
+ assert current_url do
6
+ current_url.end_with? "/another.html"
7
+ end
8
+
9
+ back
10
+
11
+ assert current_url do
12
+ current_url.end_with? "/"
13
+ end
14
+
15
+ forward
16
+
17
+ assert current_url do
18
+ current_url.end_with? "/another.html"
19
+ end
20
+
21
+ back
22
+
23
+ visit "/__superbara/wait"
24
+
25
+ wait 0.8 do
26
+ has_text? "500ms"
27
+ end
28
+
29
+ reload
30
+
31
+ assert text do
32
+ ! text.match? "500ms"
33
+ end
34
+
35
+ wait 0.8 do
36
+ has_text? "500ms"
37
+ end
@@ -1,7 +1,11 @@
1
+ run "../common"
2
+
1
3
  visit "/__superbara/prompt"
2
4
 
3
5
  message = accept_prompt with: 'Linda Liukas' do
4
6
  click_link 'Author Quiz!'
5
7
  end
6
8
 
7
- fail unless message == 'Who is the author of Hello Ruby?'
9
+ assert message do
10
+ message == 'Who is the author of Hello Ruby?'
11
+ end
@@ -1,4 +1,4 @@
1
- visit "/"
1
+ run "../common"
2
2
 
3
3
  textarea = find "textarea"
4
4
  textarea.type "hello", :backspace, :backspace, "sinki", :enter
@@ -1,6 +1,10 @@
1
+ run "../common"
2
+
1
3
  visit "/__superbara/wait"
2
4
 
3
- fail if has_text? "500ms"
5
+ assert do
6
+ has_no_text? "500ms"
7
+ end
4
8
 
5
9
  wait 0.8 do
6
10
  has_text? "500ms"
@@ -0,0 +1,3 @@
1
+ run "../common", once: true do
2
+ puts "common already loaded"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matti Paksula
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-17 00:00:00.000000000 Z
11
+ date: 2018-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -230,6 +230,26 @@ dependencies:
230
230
  - - ">="
231
231
  - !ruby/object:Gem::Version
232
232
  version: 3.7.0
233
+ - !ruby/object:Gem::Dependency
234
+ name: kommando
235
+ requirement: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '0.1'
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: 0.1.2
243
+ type: :development
244
+ prerelease: false
245
+ version_requirements: !ruby/object:Gem::Requirement
246
+ requirements:
247
+ - - "~>"
248
+ - !ruby/object:Gem::Version
249
+ version: '0.1'
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: 0.1.2
233
253
  description: Better way to build Capybara tests
234
254
  email:
235
255
  - matti.paksula@iki.fi
@@ -252,16 +272,10 @@ files:
252
272
  - bin/autotest
253
273
  - bin/console
254
274
  - bin/release
275
+ - bin/tests
255
276
  - docker-compose.build.yml
256
277
  - docker-compose.test.yml
257
278
  - docker-compose.yml
258
- - e2e/example.rb
259
- - e2e/init.rb
260
- - e2e/main.rb
261
- - e2e/prompt.rb
262
- - e2e/type.rb
263
- - e2e/vars.rb
264
- - e2e/wait.rb
265
279
  - exe/superbara
266
280
  - lib/capybara_monkey.rb
267
281
  - lib/pry_monkey.rb
@@ -276,6 +290,18 @@ files:
276
290
  - lib/superbara/version.rb
277
291
  - lib/superbara/web.rb
278
292
  - superbara.gemspec
293
+ - tests/all/main.rb
294
+ - tests/common/main.rb
295
+ - tests/common/vars.rb
296
+ - tests/common/webapp.rb
297
+ - tests/fail/main.rb
298
+ - tests/features/examplecom.rb
299
+ - tests/features/find.rb
300
+ - tests/features/navigate.rb
301
+ - tests/features/prompt.rb
302
+ - tests/features/type.rb
303
+ - tests/features/wait.rb
304
+ - tests/minimal/main.rb
279
305
  - web/public/1.html
280
306
  - web/public/2.html
281
307
  - web/public/3.html
data/e2e/example.rb DELETED
@@ -1,7 +0,0 @@
1
- wait 5 do
2
- visit "example.com"
3
- end
4
-
5
- wait 5 do
6
- has_text? "Example Domain"
7
- end
data/e2e/main.rb DELETED
@@ -1,17 +0,0 @@
1
- run "init", once: true
2
- run "vars"
3
-
4
- visit "#{$test_host}:4567"
5
- wait "3" do
6
- has_text? "Superbara"
7
- end
8
-
9
- run "wait"
10
- run "prompt"
11
- run "type"
12
-
13
- run "example", once: true do
14
- visit "example.com"
15
- end
16
-
17
- find "h1"