snapshot_ui 0.1.0 → 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: db2e79495a612dd8f9e73f84537b5237c214faf5290915f40a451b27c517fb10
4
- data.tar.gz: 5f68e150a5439073be54508096b9a085277d1cfe03292a78e396c6f790c17a0d
3
+ metadata.gz: ed5906abe86dd34b16173cdbff8239e7f649ab4ace8adceabf250c90165b1879
4
+ data.tar.gz: fce78cca8afc9baffd515257e1f5e7a564e27d803b6c2e3a84341441254d7ead
5
5
  SHA512:
6
- metadata.gz: e20faf53a0f05035d90e76e10d08a7a067728899df4bc6e5dc9c3dda944c7414579b334650c4b9a8edfc1ad2889bb7b65537d22120cb9cbc2a92b4b0378d2598
7
- data.tar.gz: c6fa887d47cfec6bf20f91146e37f0165655601b4d3a38bb43e74b735dcde65da4453a672d147cb305f0cc67dc4d5338ece722b7224f428527917e8f49b30370
6
+ metadata.gz: 2c64f1972c0f1261fe57e09e8aad3e9e9ba174184dbc9ff82ed988012e27a8d2340818629189d90a41d3ea7f2d11725ff9ec546500b32a1c0adddf6d2ec083a7
7
+ data.tar.gz: 791edbd08ad2eaffed422b850063dc8b3c5914a2214f8914f2079607c03a6c0b3cfa8b6608618e4d54750953886b633a9a7d26f3c975c8e06f5ced609f533b1f
data/README.md CHANGED
@@ -1,16 +1,8 @@
1
- # SnapshotUI
1
+ # Snapshot UI
2
2
 
3
- ## Things to do next
3
+ Take snapshots of responses in integration tests, and display them in a browser.
4
4
 
5
- - Live reloads after a test run and new snapshots become published
6
- - Accept not only "response" objects but also just plain strings for testing UI helpers (think buttons, etc.)
7
- - Make it easier to navigate between a list of snapshots and the code
8
- - Ability to disable or enable javascript of the rendered snapshots
9
-
10
- ## Things to do in the far future
11
-
12
- - Different representations of snapshot lists
13
- - Spatially display snapshots and how they connect to each other to demonstrate UI flows
14
- - Extract more information out of response snapshots - path, page title, how they connect to other snapshots
15
- - Possibility to add notes to snapshots from within tests (`take_snapshot response, note: "...")
5
+ Works with any kind of Rack application and minitest testing framework.
16
6
 
7
+ > ℹ️ The Snapshot UI is the next generation of a similar library, [Snapshot Inspector](https://github.com/tomazzlender/snapshot_inspector).
8
+ > It works with any kind of Rack application, not just Rails applications. Future development will take place here, and Snapshot Inspector will be eventually archived.
@@ -0,0 +1,30 @@
1
+ require "snapshot_ui"
2
+ require "minitest"
3
+
4
+ module Minitest
5
+ class << self
6
+ def plugin_snapshot_ui_options(opts, _options)
7
+ opts.on "--take-snapshots", "Take UI snapshots" do
8
+ ENV["TAKE_SNAPSHOTS"] = "true"
9
+ end
10
+ end
11
+
12
+ def plugin_snapshot_ui_init(_options)
13
+ return unless SnapshotUI.snapshot_taking_enabled?
14
+
15
+ SnapshotUI.exit_if_not_configured!
16
+
17
+ reporter << SnapshotUIReporter.new
18
+
19
+ SnapshotUI.clear_snapshots_in_progress
20
+ end
21
+ end
22
+
23
+ class SnapshotUIReporter < Reporter
24
+ def report
25
+ SnapshotUI.publish_snapshots_in_progress
26
+
27
+ io.puts "\n\nUI snapshots are ready for review at #{SnapshotUI.configuration.web_url}"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SnapshotUI
4
+ module Colorize
5
+ module_function
6
+
7
+ def red(string)
8
+ "\e[31m#{string}\e[0m"
9
+ end
10
+
11
+ def green(string)
12
+ "\e[32m#{string}\e[0m"
13
+ end
14
+ end
15
+ end
@@ -1,20 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "colorize"
4
+
3
5
  module SnapshotUI
4
6
  class Configuration
5
7
  attr_writer :storage_directory, :project_root_directory
8
+ attr_accessor :web_url
6
9
 
7
- def initialize(project_root_directory:, storage_directory:)
10
+ def initialize(project_root_directory:, storage_directory:, web_url:)
8
11
  @project_root_directory = project_root_directory
9
12
  @storage_directory = storage_directory
13
+ @web_url = web_url
10
14
  end
11
15
 
12
16
  def storage_directory
13
- Pathname.new(@storage_directory)
17
+ Pathname.new(@storage_directory) if @storage_directory
14
18
  end
15
19
 
16
20
  def project_root_directory
17
- Pathname.new(@project_root_directory)
21
+ Pathname.new(@project_root_directory) if @project_root_directory
22
+ end
23
+
24
+ def exit_if_not_configured!
25
+ return unless project_root_directory.nil? || storage_directory.nil? || web_url.nil?
26
+
27
+ puts Colorize.red("Looks like SnapshotUI is not configured yet. Example configuration:\n")
28
+
29
+ puts <<~CONFIG
30
+ #{Colorize.green("SnapshotUI.configure do |config|")}
31
+ #{Colorize.green('config.storage_directory = "/path/to/tmp/snapshot_ui"')} #{Colorize.red("# Current value is `#{storage_directory.inspect}`")}
32
+ #{Colorize.green('config.project_root_directory = "/path/to/project/root"')} #{Colorize.red("# Current value is `#{project_root_directory.inspect}`")}
33
+ #{Colorize.green("config.web_url = \"#{web_url}\"")} #{Colorize.red("# Current value is `#{web_url.inspect}`")}
34
+ #{Colorize.green("end")}
35
+
36
+ CONFIG
37
+
38
+ raise SystemExit.new(1)
18
39
  end
19
40
  end
20
41
  end
@@ -16,6 +16,8 @@ module SnapshotUI
16
16
  raise ArgumentError.new(message)
17
17
  end
18
18
 
19
+ SnapshotUI.exit_if_not_configured!
20
+
19
21
  increment_take_snapshot_counter_scoped_by_test
20
22
 
21
23
  SnapshotUI::Snapshot.persist(
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SnapshotUI
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/snapshot_ui.rb CHANGED
@@ -5,8 +5,9 @@ require_relative "snapshot_ui/configuration"
5
5
 
6
6
  module SnapshotUI
7
7
  DEFAULT_CONFIGURATION = {
8
- project_root_directory: ".",
9
- storage_directory: "tmp/snapshot_ui"
8
+ project_root_directory: nil,
9
+ storage_directory: nil,
10
+ web_url: "http://localhost:3000/ui/snapshots"
10
11
  }.freeze
11
12
 
12
13
  def self.configure
@@ -22,14 +23,24 @@ module SnapshotUI
22
23
  end
23
24
 
24
25
  def self.publish_snapshots_in_progress
26
+ exit_if_not_configured!
27
+
25
28
  Snapshot.publish_snapshots_in_progress
26
29
  end
27
30
 
28
31
  def self.clear_snapshots_in_progress
32
+ exit_if_not_configured!
33
+
29
34
  Snapshot.clear_snapshots_in_progress
30
35
  end
31
36
 
32
37
  def self.clear_snapshots
38
+ exit_if_not_configured!
39
+
33
40
  Snapshot.clear_snapshots
34
41
  end
42
+
43
+ def self.exit_if_not_configured!
44
+ configuration.exit_if_not_configured!
45
+ end
35
46
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snapshot_ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomaz Zlender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -92,9 +92,11 @@ files:
92
92
  - LICENSE.txt
93
93
  - README.md
94
94
  - bin/snapshot_ui
95
+ - lib/minitest/snapshot_ui_plugin.rb
95
96
  - lib/snapshot_ui.rb
96
97
  - lib/snapshot_ui/cli.rb
97
98
  - lib/snapshot_ui/cli/watcher.ru
99
+ - lib/snapshot_ui/colorize.rb
98
100
  - lib/snapshot_ui/configuration.rb
99
101
  - lib/snapshot_ui/snapshot.rb
100
102
  - lib/snapshot_ui/snapshot/context.rb