capybara-wsl 0.2.1 → 0.3.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: 04e04f7c677729e9d7e3548f5982a69bbaf858e7f55834fa41b5fa5f394c2764
4
- data.tar.gz: 89c9fd0d1aa1df15315587904f0a40157c93120d2078d61f4e989b21b725b186
3
+ metadata.gz: c268d40e531e50a7d5acc3542da8f8b8ff97f2e1f51706792ffcd3641fcd8040
4
+ data.tar.gz: 0b013a92616e617b2b3eec67275e36041a627cf157792bf7ed3070ef335c97ba
5
5
  SHA512:
6
- metadata.gz: 62f5848e003552e5df7c55619cc30942d2367c031130a9f1cc54e408235be55cba80decb8c65a3fbd10156c677575fec04d89a27af8d40e4b686c091679ef70a
7
- data.tar.gz: b4e65eae735cf4d12bce4599d443e2080a6dd8a2778e9862b966d24f2085320fd1cb2295e857ea5bf07cc2cfbbb444c4ca0c4183e3f2302f44473fe436494bc8
6
+ metadata.gz: dfcccaf4c7b83b9168cc2094f29b766616553dc1725d7646ca2644a3beb793008975d71291442371c22790935423f1172115e35a3af797e6f0bd7449da79a9c0
7
+ data.tar.gz: cdd13d5a4d73419ab540daaae213482962785e8a327024b7bf4f6afeb6c1b35cce20dbe642ca708b178a0f093ff2121b4a67f1aac90cd86582ad380d10ea4c53
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capybara-wsl (0.2.1)
5
+ capybara (>= 2.0)
6
+ launchy (>= 2.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ capybara (3.33.0)
14
+ addressable
15
+ mini_mime (>= 0.1.3)
16
+ nokogiri (~> 1.8)
17
+ rack (>= 1.6.0)
18
+ rack-test (>= 0.6.3)
19
+ regexp_parser (~> 1.5)
20
+ xpath (~> 3.2)
21
+ launchy (2.5.0)
22
+ addressable (~> 2.7)
23
+ mini_mime (1.0.2)
24
+ mini_portile2 (2.4.0)
25
+ nokogiri (1.10.10)
26
+ mini_portile2 (~> 2.4.0)
27
+ public_suffix (4.0.5)
28
+ rack (2.2.3)
29
+ rack-test (1.1.0)
30
+ rack (>= 1.0, < 3)
31
+ regexp_parser (1.7.1)
32
+ xpath (3.2.0)
33
+ nokogiri (~> 1.8)
34
+
35
+ PLATFORMS
36
+ ruby
37
+
38
+ DEPENDENCIES
39
+ capybara-wsl!
40
+
41
+ BUNDLED WITH
42
+ 2.1.4
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
- CapybaraWSL
1
+ capybara-wsl
2
2
  =======================
3
3
  [![Gem Version](https://badge.fury.io/rb/capybara-wsl.svg)](https://badge.fury.io/rb/capybara-wsl)
4
4
 
5
5
  #### Allows you use open saved pages from WSL
6
6
 
7
- Capybara's `save_and_open_page` and `save_and_open_screenshot` methods don't work properly in WSL. It saves pages/screenshots, but when it tries to open them via Launchy, it passes Linux path, which obviously wouldn't work in Windows browsers.
7
+ Capybara's `save_and_open_page` and `save_and_open_screenshot` methods don't work properly in WSL. Capybara saves pages/screenshots, but then it tries to open them via Launchy and there are several problems with that. We don't want to mess with GUI on WSL, we just want to open them in a Windows browser. However, Capybara passes a Linux path to Launchy, which obviously wouldn't work in Windows browsers.
8
8
 
9
- This gem modifies that path to include `wsl$` part so that it's understandable for Windows browsers.
9
+ This gem modifies that path to include `wsl$` part so that it's understandable for Windows browsers. It automatically detects your current WSL distro (since version 0.3.0).
10
10
 
11
11
  ### Installation
12
12
  In your `Gemfile` add:
@@ -20,15 +20,15 @@ Or `gem install capybara-wsl`, but then running it is a bit less straightforward
20
20
  ### Important note
21
21
  In order for it to work, you have to add `$BROWSER` env variable.
22
22
  ###### Example for Firefox
23
- In your `.bashrc` add:
23
+ In your `.bashrc` add (notice the quotes):
24
24
  ```
25
- export BROWSER='/mnt/c/Program Files/Mozilla Firefox/firefox.exe'
25
+ export BROWSER="'/mnt/c/Program Files/Mozilla Firefox/firefox.exe'"
26
26
  ```
27
27
 
28
28
  ### Usage
29
29
  Simply use
30
30
  `save_and_open_page_wsl` or
31
- `save_and_open_screenshot_wsl` instead of their normal versions.
31
+ `save_and_open_screenshot_wsl` instead of their normal versions. You can use same arguments.
32
32
 
33
33
  If you installed via `gem install`:
34
34
  Run `gem which capybara-wsl` in your console and copy output.
@@ -38,8 +38,3 @@ Simply use
38
38
  Capybara::WSL.save_and_open_page
39
39
  Capybara::WSL.save_and_open_screenshot
40
40
  ```
41
-
42
- CapybaraWSL converts page/screenshot path to WSL Ubuntu path by default. If you have another distro, please set the `distro` setting `Capybara::WSL.distro = :debian` to whichever distro you are using.
43
- You can look up available distro keys in `Capybara::WSL::DISTROS`. You can also set `distro` to a string with exact folder name of your distro `Capybara::WSL.distro = "openSUSE-Leap-15-1"`.
44
-
45
- Please tell me if some of those distro folder names in `Capybara::WSL::DISTROS` are incorrect, I don't really have a way to check it.
@@ -2,51 +2,45 @@
2
2
 
3
3
  require "capybara"
4
4
  require "capybara/dsl"
5
- require_relative "wsl/distros"
6
5
  require_relative "wsl/dsl"
7
6
 
8
7
  module Capybara
9
8
  module WSL
10
9
  class CapybaraWSLError < StandardError; end
11
- class DistroKeyNotSupported < CapybaraWSLError; end
10
+ class CannotDetectWSLPath < CapybaraWSLError; end
12
11
 
13
12
  def self.save_and_open_page(path = nil)
14
13
  Capybara.current_session.save_page(path).tap do |s_path|
15
- wsl_path = modify_path(s_path)
16
- Capybara.current_session.send(:open_file, wsl_path)
14
+ open_file(s_path)
17
15
  end
18
16
  end
19
17
 
20
18
  def self.save_and_open_screenshot(path = nil, **options)
21
19
  Capybara.current_session.save_screenshot(path, options).tap do |s_path|
22
- wsl_path = modify_path(s_path)
23
- Capybara.current_session.send(:open_file, wsl_path)
20
+ open_file(s_path)
24
21
  end
25
22
  end
26
23
 
27
- def self.distro
28
- @distro || :ubuntu
29
- end
30
-
31
- def self.distro=(name)
32
- if name.is_a?(Symbol) && DISTROS[name].nil?
33
- raise(Capybara::WSL::DistroKeyNotSupported,
34
- "This distro key is not supported. Please use supported key or pass a string with exact distro folder name.")
35
- end
24
+ private
36
25
 
37
- @distro = name
26
+ def self.open_file(path)
27
+ wsl_path = modify_path(path)
28
+ Capybara.current_session.send(:open_file, wsl_path)
38
29
  end
39
30
 
40
- private
41
-
42
31
  def self.modify_path(path)
43
- path.prepend("file://///wsl$/#{distro_folder_name}")
32
+ path.prepend(detect_path)
44
33
  end
45
34
 
46
- def self.distro_folder_name
47
- return distro if distro.is_a?(String)
35
+ def self.detect_path
36
+ path = `wslpath -m "/"`&.strip
37
+
38
+ if path.empty?
39
+ raise(Capybara::WSL::CannotDetectWSLPath,
40
+ "Cannot detect WSL path. Are you sure you're running WSL?")
41
+ end
48
42
 
49
- DISTROS[distro]
43
+ "file:///#{path}"
50
44
  end
51
45
  end
52
46
  end
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Capybara
2
4
  module WSL
3
5
  module DSL
4
- def save_and_open_page_wsl
5
- Capybara::WSL.save_and_open_page
6
+ def save_and_open_page_wsl(path = nil)
7
+ Capybara::WSL.save_and_open_page(path)
6
8
  end
7
9
 
8
- def save_and_open_screenshot_wsl
9
- Capybara::WSL.save_and_open_screenshot
10
+ def save_and_open_screenshot_wsl(path = nil, **options)
11
+ Capybara::WSL.save_and_open_screenshot(path, options)
10
12
  end
11
13
  end
12
14
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Capybara
4
4
  module WSL
5
- VERSION = "0.2.1"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara-wsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Tityuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -45,11 +45,11 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - Gemfile
48
+ - Gemfile.lock
48
49
  - README.md
49
50
  - capybara-wsl.gemspec
50
51
  - lib/capybara-wsl.rb
51
52
  - lib/capybara/wsl.rb
52
- - lib/capybara/wsl/distros.rb
53
53
  - lib/capybara/wsl/dsl.rb
54
54
  - lib/capybara/wsl/version.rb
55
55
  homepage: https://github.com/dersnek/capybara-wsl
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Capybara
4
- module WSL
5
- DISTROS = {
6
- alpine: "Alpine-WSL",
7
- centos: "CentOS",
8
- debian: "Debian",
9
- fedors: "Fedora-Remix-for-WSL",
10
- kali: "kali-linux",
11
- opensuse: "openSUSE-Leap-15-1",
12
- pengwin: "Pengwin",
13
- ubuntu: "Ubuntu",
14
- }.freeze
15
- end
16
- end