snapshot_ui 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63bfd50e7e9795cf6ea6ef899d84d07aa333fbfe309e79f3476e2686fceae58f
4
- data.tar.gz: d524af4e1ef098840a7119685d8a60c27301cb5b6bf91064b0350011535e3d58
3
+ metadata.gz: ed5906abe86dd34b16173cdbff8239e7f649ab4ace8adceabf250c90165b1879
4
+ data.tar.gz: fce78cca8afc9baffd515257e1f5e7a564e27d803b6c2e3a84341441254d7ead
5
5
  SHA512:
6
- metadata.gz: b5756f817fb9f6c7f73f0dcf61aa9436698826fc1ef6a0722cd9a53eb2ea201cb4aa30615a33a443170fc16874f83d52ee8dfd40017d9f59a258ff9c64af0cc9
7
- data.tar.gz: 8cad2af17162a97a97bf84837b39063eef97d57ec2835675498d98507f425d07a01956645fb86b6f92592493ed08c76a2ac84eb476d9a79bb73c7fd0b3133137
6
+ metadata.gz: 2c64f1972c0f1261fe57e09e8aad3e9e9ba174184dbc9ff82ed988012e27a8d2340818629189d90a41d3ea7f2d11725ff9ec546500b32a1c0adddf6d2ec083a7
7
+ data.tar.gz: 791edbd08ad2eaffed422b850063dc8b3c5914a2214f8914f2079607c03a6c0b3cfa8b6608618e4d54750953886b633a9a7d26f3c975c8e06f5ced609f533b1f
@@ -12,6 +12,8 @@ module Minitest
12
12
  def plugin_snapshot_ui_init(_options)
13
13
  return unless SnapshotUI.snapshot_taking_enabled?
14
14
 
15
+ SnapshotUI.exit_if_not_configured!
16
+
15
17
  reporter << SnapshotUIReporter.new
16
18
 
17
19
  SnapshotUI.clear_snapshots_in_progress
@@ -22,7 +24,7 @@ module Minitest
22
24
  def report
23
25
  SnapshotUI.publish_snapshots_in_progress
24
26
 
25
- io.print "\n\nUI snapshots are ready for review at #{SnapshotUI.configuration.web_url}"
27
+ io.puts "\n\nUI snapshots are ready for review at #{SnapshotUI.configuration.web_url}"
26
28
  end
27
29
  end
28
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,5 +1,7 @@
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
@@ -12,11 +14,28 @@ module SnapshotUI
12
14
  end
13
15
 
14
16
  def storage_directory
15
- Pathname.new(@storage_directory)
17
+ Pathname.new(@storage_directory) if @storage_directory
16
18
  end
17
19
 
18
20
  def project_root_directory
19
- 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)
20
39
  end
21
40
  end
22
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.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/snapshot_ui.rb CHANGED
@@ -5,8 +5,8 @@ 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
10
  web_url: "http://localhost:3000/ui/snapshots"
11
11
  }.freeze
12
12
 
@@ -23,14 +23,24 @@ module SnapshotUI
23
23
  end
24
24
 
25
25
  def self.publish_snapshots_in_progress
26
+ exit_if_not_configured!
27
+
26
28
  Snapshot.publish_snapshots_in_progress
27
29
  end
28
30
 
29
31
  def self.clear_snapshots_in_progress
32
+ exit_if_not_configured!
33
+
30
34
  Snapshot.clear_snapshots_in_progress
31
35
  end
32
36
 
33
37
  def self.clear_snapshots
38
+ exit_if_not_configured!
39
+
34
40
  Snapshot.clear_snapshots
35
41
  end
42
+
43
+ def self.exit_if_not_configured!
44
+ configuration.exit_if_not_configured!
45
+ end
36
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.2.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-24 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
@@ -96,6 +96,7 @@ files:
96
96
  - lib/snapshot_ui.rb
97
97
  - lib/snapshot_ui/cli.rb
98
98
  - lib/snapshot_ui/cli/watcher.ru
99
+ - lib/snapshot_ui/colorize.rb
99
100
  - lib/snapshot_ui/configuration.rb
100
101
  - lib/snapshot_ui/snapshot.rb
101
102
  - lib/snapshot_ui/snapshot/context.rb