hirber 0.8.2 → 0.8.4
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 +4 -4
- data/.gemspec +38 -7
- data/CHANGELOG.rdoc +9 -0
- data/README.md +3 -1
- data/Rakefile +14 -8
- data/lib/hirb/version.rb +1 -1
- data/lib/hirb/view.rb +39 -14
- data/spec/spec_helper.rb +61 -0
- data/spec/view_spec.rb +276 -0
- data/spec/views_spec.rb +54 -0
- data/test/test_helper.rb +9 -5
- metadata +35 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bb901afec50ad8300985c7f84d2a2296c9b8a6478287cbbb4d37fcfa3189a6d
|
4
|
+
data.tar.gz: 1de8e4cb4045f3ceea7bdab47b577d6dd001fe5228ada5bb899893b56a03b5f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a6d83f529532ed0aed83ab8304a11abb729c667f706fc5b519e8cd0c5d83cc748ead769f9ca3e95fd0a7a6d08b659335e4de36c0f2ea1e4cb8105e5844edc6d
|
7
|
+
data.tar.gz: ed949ee1a4de44b2cf34f47104526516987e88fb5a0d05cde04496c9dcd39063d1a881e0953fe9f7fd9aea44289dc11eac11a90e3eac9c555e0bf9fe7f415b9e
|
data/.gemspec
CHANGED
@@ -1,23 +1,54 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require
|
2
|
+
require "rubygems" unless Object.const_defined?(:Gem)
|
3
3
|
require File.dirname(__FILE__) + "/lib/hirb/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "hirber"
|
7
7
|
s.version = Hirb::VERSION
|
8
|
-
|
9
|
-
s.
|
8
|
+
|
9
|
+
s.authors = ["Gabriel Horner", "Aleksander Długopolski"]
|
10
|
+
s.email = "ad@dotpro.org"
|
10
11
|
s.homepage = "http://tagaholic.me/hirb/"
|
11
|
-
|
12
|
-
s.
|
12
|
+
|
13
|
+
s.summary = <<~TXT.gsub(/[[:space:]]+/, " ").strip
|
14
|
+
A mini view framework for console/irb that's easy to use, even while under
|
15
|
+
its influence.
|
16
|
+
TXT
|
17
|
+
|
18
|
+
s.description = <<~TXT.gsub(/[[:space:]]+/, " ").strip
|
19
|
+
Hirb provides a mini view framework for console applications and uses
|
20
|
+
it to improve ripl(irb)'s default inspect output. Given an object or
|
21
|
+
array of objects, hirb renders a view based on the object's class and/or
|
22
|
+
ancestry. Hirb offers reusable views in the form of helper classes. The
|
23
|
+
two main helpers, Hirb::Helpers::Table and Hirb::Helpers::Tree,
|
24
|
+
provide several options for generating ascii tables and trees. Using
|
25
|
+
Hirb::Helpers::AutoTable, hirb has useful default views for at least ten
|
26
|
+
popular database gems i.e. Rails' ActiveRecord::Base. Other than views,
|
27
|
+
hirb offers a smart pager and a console menu. The smart pager only pages
|
28
|
+
when the output exceeds the current screen size. The menu is used in
|
29
|
+
conjunction with tables to offer two dimensional menus.
|
30
|
+
TXT
|
31
|
+
|
13
32
|
s.required_rubygems_version = ">= 1.3.5"
|
14
33
|
|
34
|
+
s.add_development_dependency "rake"
|
35
|
+
s.add_development_dependency "rspec", ">= 3.9"
|
15
36
|
s.add_development_dependency "bacon", "~> 1.1"
|
16
37
|
s.add_development_dependency "mocha", "~> 0.12.1"
|
17
38
|
s.add_development_dependency "mocha-on-bacon", "~> 0.2.1"
|
18
39
|
s.add_development_dependency "bacon-bits", "~> 0.1"
|
19
40
|
|
20
|
-
s.files =
|
41
|
+
s.files =
|
42
|
+
Dir.glob %w[
|
43
|
+
{lib,test,spec}/**/*.rb
|
44
|
+
bin/*
|
45
|
+
[A-Z]*.{txt,rdoc,md}
|
46
|
+
ext/**/*.{rb,c}
|
47
|
+
Rakefile
|
48
|
+
.gemspec
|
49
|
+
.travis.yml
|
50
|
+
]
|
51
|
+
|
21
52
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
22
|
-
s.license =
|
53
|
+
s.license = "MIT"
|
23
54
|
end
|
data/CHANGELOG.rdoc
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+

|
2
|
+
|
1
3
|
## Preface
|
2
4
|
|
3
5
|
This gem is a direct fork of [Hirb](https://github.com/cldwalker/hirb) (0.7.3)
|
@@ -23,7 +25,7 @@ size. The menu is used in conjunction with tables to offer [two dimensional menu
|
|
23
25
|
|
24
26
|
Install the gem with:
|
25
27
|
|
26
|
-
gem install
|
28
|
+
gem install hirber
|
27
29
|
|
28
30
|
For people using full-width unicode characters, install
|
29
31
|
[hirb-unicode](https://github.com/miaout17/hirb-unicode):
|
data/Rakefile
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rake"
|
2
|
+
require "fileutils"
|
3
3
|
|
4
4
|
def gemspec
|
5
|
-
@gemspec ||= eval(File.read(
|
5
|
+
@gemspec ||= eval(File.read(".gemspec"), binding, ".gemspec")
|
6
6
|
end
|
7
7
|
|
8
8
|
desc "Build the gem"
|
9
|
-
task :gem
|
9
|
+
task :gem => :gemspec do
|
10
10
|
sh "gem build .gemspec"
|
11
|
-
|
12
|
-
FileUtils.
|
11
|
+
|
12
|
+
FileUtils.mkdir_p "pkg"
|
13
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", "pkg"
|
13
14
|
end
|
14
15
|
|
15
16
|
desc "Install the gem locally"
|
@@ -27,9 +28,14 @@ task :gemspec do
|
|
27
28
|
gemspec.validate
|
28
29
|
end
|
29
30
|
|
30
|
-
desc
|
31
|
+
desc "Run spec"
|
32
|
+
task :spec do
|
33
|
+
sh "rspec"
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "Run tests"
|
31
37
|
task :test do |t|
|
32
|
-
sh
|
38
|
+
sh "bacon -q -Ilib -I. test/*_test.rb"
|
33
39
|
end
|
34
40
|
|
35
41
|
task :default => :test
|
data/lib/hirb/version.rb
CHANGED
data/lib/hirb/view.rb
CHANGED
@@ -108,17 +108,25 @@ module Hirb
|
|
108
108
|
config[:formatter] = !config[:formatter]
|
109
109
|
end
|
110
110
|
|
111
|
-
# Resizes the console width and height for use with the table and pager
|
112
|
-
#
|
113
|
-
#
|
111
|
+
# Resizes the console width and height for use with the table and pager
|
112
|
+
# i.e. after having resized the console window. *nix users should only
|
113
|
+
# have to call this method. Non-*nix users should call this method with
|
114
|
+
# explicit width and height. If you don't know your width and height, in
|
115
|
+
# irb play with "a"* width to find width and puts "a\n" * height to find
|
116
|
+
# height.
|
117
|
+
|
114
118
|
def resize(width=nil, height=nil)
|
115
119
|
config[:width], config[:height] = determine_terminal_size(width, height)
|
116
120
|
pager.resize(config[:width], config[:height])
|
117
121
|
end
|
118
122
|
|
119
|
-
# This is the main method of this class. When view is enabled,
|
120
|
-
#
|
121
|
-
#
|
123
|
+
# This is the main method of this class. When view is enabled,
|
124
|
+
# this method searches for a formatter it can use for the output
|
125
|
+
# and if successful renders it using render_method(). The options
|
126
|
+
# this method takes are helper config hashes as described in
|
127
|
+
# Hirb::Formatter.format_output(). Returns true if successful and false
|
128
|
+
# if no formatting is done or if not enabled.
|
129
|
+
|
122
130
|
def view_output(output, options={})
|
123
131
|
enabled? && config[:formatter] && render_output(output, options)
|
124
132
|
rescue Exception=>e
|
@@ -179,8 +187,18 @@ module Hirb
|
|
179
187
|
if defined?(Ripl) && Ripl.respond_to?(:started?) && Ripl.started?
|
180
188
|
@output_method = true
|
181
189
|
require 'ripl/hirb' unless defined? Ripl::Hirb
|
182
|
-
|
190
|
+
|
191
|
+
elsif defined? Pry
|
192
|
+
original_print = Pry.config.print
|
193
|
+
|
194
|
+
Pry.config.print = proc do |output, result, pry_instance|
|
195
|
+
Hirb::View.view_or_page_output(result) ||
|
196
|
+
original_print.call(output, result, pry_instance)
|
197
|
+
end
|
198
|
+
|
199
|
+
elsif defined?(IRB::Irb)
|
183
200
|
@output_method = true
|
201
|
+
|
184
202
|
::IRB::Irb.class_eval do
|
185
203
|
alias_method :non_hirb_view_output, :output_value
|
186
204
|
|
@@ -191,11 +209,14 @@ module Hirb
|
|
191
209
|
|
192
210
|
# Do not pass the value if the default is given to keep backwards
|
193
211
|
# compatiblity for Ruby =< 2.7.1
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
212
|
+
|
213
|
+
if !instance_methods(false).include?(:original_output_value)
|
214
|
+
def original_output_value(omit)
|
215
|
+
if omit
|
216
|
+
non_hirb_view_output(omit)
|
217
|
+
else
|
218
|
+
non_hirb_view_output
|
219
|
+
end
|
199
220
|
end
|
200
221
|
end
|
201
222
|
end
|
@@ -203,8 +224,12 @@ module Hirb
|
|
203
224
|
end
|
204
225
|
|
205
226
|
def disable_output_method
|
206
|
-
if defined?(IRB::Irb) && !defined?
|
207
|
-
::IRB::Irb.
|
227
|
+
if defined?(IRB::Irb) && !defined?(Ripl)
|
228
|
+
::IRB::Irb.class_eval do
|
229
|
+
undef output_value
|
230
|
+
|
231
|
+
alias_method :output_value, :non_hirb_view_output
|
232
|
+
end
|
208
233
|
end
|
209
234
|
@output_method = nil
|
210
235
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module RSpec::Helpers
|
2
|
+
ENV["LINES"] = ENV["COLUMNS"] = "20"
|
3
|
+
|
4
|
+
def reset_config
|
5
|
+
Hirb::View.instance_eval do
|
6
|
+
@config = nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def capture_stderr(&block)
|
11
|
+
original_stderr = $stderr
|
12
|
+
$stderr = fake = StringIO.new
|
13
|
+
begin
|
14
|
+
yield
|
15
|
+
ensure
|
16
|
+
$stderr = original_stderr
|
17
|
+
end
|
18
|
+
fake.string
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset_terminal_size
|
22
|
+
ENV["LINES"] = ENV["COLUMNS"] = "20"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module ::IRB
|
27
|
+
class Irb
|
28
|
+
def initialize(context)
|
29
|
+
@context = context
|
30
|
+
end
|
31
|
+
|
32
|
+
def output_value; end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
include RSpec::Helpers
|
38
|
+
|
39
|
+
config.expect_with :rspec do |expectations|
|
40
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
41
|
+
end
|
42
|
+
|
43
|
+
config.mock_with :rspec do |mocks|
|
44
|
+
mocks.verify_partial_doubles = true
|
45
|
+
end
|
46
|
+
|
47
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
48
|
+
config.filter_run_when_matching :focus
|
49
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
50
|
+
config.disable_monkey_patching!
|
51
|
+
config.warnings = true
|
52
|
+
|
53
|
+
if config.files_to_run.one?
|
54
|
+
config.default_formatter = "doc"
|
55
|
+
end
|
56
|
+
|
57
|
+
config.profile_examples = 5
|
58
|
+
config.order = :random
|
59
|
+
|
60
|
+
Kernel.srand config.seed
|
61
|
+
end
|
data/spec/view_spec.rb
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
require "hirber"
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
RSpec.describe "Hirb::View" do
|
5
|
+
it "page_output pages when view is enabled" do
|
6
|
+
reset_config
|
7
|
+
|
8
|
+
Hirb.enable
|
9
|
+
|
10
|
+
allow(Hirb::View.pager).to receive_messages(activated_by?: true)
|
11
|
+
expect(Hirb::View.pager).to receive(:page)
|
12
|
+
expect(Hirb::View.page_output("blah")).to be(true)
|
13
|
+
|
14
|
+
Hirb.disable
|
15
|
+
end
|
16
|
+
|
17
|
+
it "page_output doesn't page when view is disabled" do
|
18
|
+
Hirb.enable
|
19
|
+
Hirb.disable
|
20
|
+
|
21
|
+
allow(Hirb::View.pager).to receive_messages(activated_by?: true)
|
22
|
+
|
23
|
+
expect(Hirb::View.pager).not_to receive(:page)
|
24
|
+
expect(Hirb::View.page_output("blah")).to be(false)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "view_output catches unexpected errors and prints them" do
|
28
|
+
reset_config
|
29
|
+
|
30
|
+
Hirb.enable
|
31
|
+
|
32
|
+
allow(::Hirb::View).to receive(:render_output).and_raise("error")
|
33
|
+
|
34
|
+
expect(capture_stderr { Hirb::View.view_output([1,2,3]) })
|
35
|
+
.to match(/Hirb Error: error/)
|
36
|
+
|
37
|
+
Hirb.disable
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "enable" do
|
41
|
+
before { reset_config }
|
42
|
+
|
43
|
+
after { Hirb.disable }
|
44
|
+
|
45
|
+
it "redefines irb output_value" do
|
46
|
+
expect(Hirb::View).to receive(:render_output)
|
47
|
+
|
48
|
+
Hirb.enable
|
49
|
+
|
50
|
+
context_stub = double(last_value: "")
|
51
|
+
|
52
|
+
::IRB::Irb.new(context_stub).output_value
|
53
|
+
end
|
54
|
+
|
55
|
+
it "is enabled?" do
|
56
|
+
reset_config
|
57
|
+
|
58
|
+
Hirb.enable
|
59
|
+
|
60
|
+
expect(Hirb::View).to be_enabled
|
61
|
+
end
|
62
|
+
|
63
|
+
def output_class_config(klass)
|
64
|
+
{ :output=>{klass=>{:class=>:auto_table}} }
|
65
|
+
end
|
66
|
+
|
67
|
+
it "sets formatter config" do
|
68
|
+
class_hash = {"Something::Base"=>{:class=>"BlahBlah"}}
|
69
|
+
|
70
|
+
Hirb.enable :output => class_hash
|
71
|
+
|
72
|
+
expect(Hirb::View.formatter_config["Something::Base"])
|
73
|
+
.to eq class_hash["Something::Base"]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "when called multiple times merges configs" do
|
77
|
+
Hirb.config = nil
|
78
|
+
# default config + config_file
|
79
|
+
|
80
|
+
allow(Hirb)
|
81
|
+
.to receive_messages(
|
82
|
+
read_config_file: output_class_config("Regexp"),
|
83
|
+
)
|
84
|
+
|
85
|
+
Hirb.enable output_class_config("String")
|
86
|
+
|
87
|
+
# add config file and explicit config
|
88
|
+
[{:config_file=>"ok"}, output_class_config("Struct")].each do |config|
|
89
|
+
expect(Hirb)
|
90
|
+
.to receive(:read_config_file)
|
91
|
+
.and_return(
|
92
|
+
output_class_config('ActiveRecord::Base'),
|
93
|
+
output_class_config('Array'),
|
94
|
+
)
|
95
|
+
|
96
|
+
Hirb.enable config
|
97
|
+
end
|
98
|
+
|
99
|
+
expect(Hirb.config_files.include?("ok")).to eq(true)
|
100
|
+
|
101
|
+
output_keys = %w{ActiveRecord::Base Array Regexp String Struct}
|
102
|
+
|
103
|
+
expect(Hirb::View.config[:output].keys.sort).to eq output_keys
|
104
|
+
end
|
105
|
+
|
106
|
+
xit "when called multiple times without config doesn't affect config" do
|
107
|
+
# FIXME: 2021-02-14 - This flapping, spec is order dependant
|
108
|
+
|
109
|
+
Hirb.enable
|
110
|
+
|
111
|
+
old_config = Hirb::View.config
|
112
|
+
|
113
|
+
expect(Hirb).not_to receive(:read_config_file)
|
114
|
+
expect(Hirb::View).not_to receive(:load_config)
|
115
|
+
|
116
|
+
# Hirb.expects(:read_config_file).never
|
117
|
+
# Hirb::View.expects(:load_config).never
|
118
|
+
|
119
|
+
Hirb.enable
|
120
|
+
|
121
|
+
expect(Hirb::View.config).to eq old_config
|
122
|
+
end
|
123
|
+
|
124
|
+
xit "works without irb" do
|
125
|
+
# FIXME: 2021-02-14 - This flapping, spec is order dependant
|
126
|
+
|
127
|
+
allow(Object)
|
128
|
+
.to receive(:const_defined?)
|
129
|
+
.with(:IRB)
|
130
|
+
.and_return(false)
|
131
|
+
|
132
|
+
Hirb.enable
|
133
|
+
|
134
|
+
expect(Hirb::View.formatter.config.size).to be > 1
|
135
|
+
end
|
136
|
+
|
137
|
+
it "with config_file option adds to config_file" do
|
138
|
+
Hirb.enable :config_file => "test_file"
|
139
|
+
|
140
|
+
expect(Hirb.config_files.include?("test_file")).to be(true)
|
141
|
+
end
|
142
|
+
|
143
|
+
it "with ignore_errors enable option" do
|
144
|
+
Hirb.enable :ignore_errors => true
|
145
|
+
|
146
|
+
expect(Hirb::View)
|
147
|
+
.to receive(:render_output)
|
148
|
+
.and_raise(Exception, "Ex mesg")
|
149
|
+
.twice
|
150
|
+
|
151
|
+
expect(Hirb::View.view_output("")).to eq(false)
|
152
|
+
|
153
|
+
expect(capture_stderr { Hirb::View.view_output("") })
|
154
|
+
.to match(/Error: Ex mesg/)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
describe "resize" do
|
159
|
+
def pager; Hirb::View.pager; end
|
160
|
+
|
161
|
+
before do
|
162
|
+
Hirb::View.pager = nil
|
163
|
+
reset_config
|
164
|
+
Hirb.enable
|
165
|
+
end
|
166
|
+
|
167
|
+
after { Hirb.disable }
|
168
|
+
|
169
|
+
it "changes width and height with stty" do
|
170
|
+
if RUBY_PLATFORM[/java/]
|
171
|
+
allow(Hirb::Util)
|
172
|
+
.to receive(:command_exists?)
|
173
|
+
.with("tput")
|
174
|
+
.and_returns(false)
|
175
|
+
end
|
176
|
+
|
177
|
+
allow(STDIN)
|
178
|
+
.to receive(:tty?)
|
179
|
+
.and_return(true)
|
180
|
+
|
181
|
+
allow(Hirb::Util)
|
182
|
+
.to receive(:command_exists?)
|
183
|
+
.with("stty")
|
184
|
+
.and_return(true)
|
185
|
+
|
186
|
+
ENV["COLUMNS"] = ENV["LINES"] = nil # bypasses env usage
|
187
|
+
|
188
|
+
capture_stderr { Hirb::View.resize }
|
189
|
+
|
190
|
+
expect(pager.width).not_to eq 10
|
191
|
+
expect(pager.height).not_to eq 10
|
192
|
+
|
193
|
+
reset_terminal_size
|
194
|
+
end
|
195
|
+
|
196
|
+
it "changes width and height with ENV" do
|
197
|
+
ENV["COLUMNS"] = ENV["LINES"] = "10" # simulates resizing
|
198
|
+
|
199
|
+
Hirb::View.resize
|
200
|
+
|
201
|
+
expect(pager.width).to eq 10
|
202
|
+
expect(pager.height).to eq 10
|
203
|
+
end
|
204
|
+
|
205
|
+
it "with no environment or stty still has valid width and height" do
|
206
|
+
Hirb::View.config[:width] = Hirb::View.config[:height] = nil
|
207
|
+
|
208
|
+
unless RUBY_PLATFORM[/java/]
|
209
|
+
allow(Hirb::Util)
|
210
|
+
.to receive(:command_exists?)
|
211
|
+
.with("stty")
|
212
|
+
.and_return(false)
|
213
|
+
end
|
214
|
+
|
215
|
+
ENV["COLUMNS"] = ENV["LINES"] = nil
|
216
|
+
|
217
|
+
Hirb::View.resize
|
218
|
+
|
219
|
+
expect(pager.width.is_a?(Integer)).to eq(true)
|
220
|
+
expect(pager.height.is_a?(Integer)).to eq(true)
|
221
|
+
|
222
|
+
reset_terminal_size
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
it "disable points output_value back to original output_value" do
|
227
|
+
expect(Hirb::View).not_to receive(:render_output)
|
228
|
+
|
229
|
+
Hirb.enable
|
230
|
+
Hirb.disable
|
231
|
+
|
232
|
+
context_stub = double(:last_value=>"")
|
233
|
+
|
234
|
+
::IRB::Irb.new(context_stub).output_value
|
235
|
+
end
|
236
|
+
|
237
|
+
it "disable works without irb defined" do
|
238
|
+
# Object.stubs(:const_defined?).with(:IRB).returns(false)
|
239
|
+
allow(Object).to receive(:const_defined?).with(:IRB).and_return(false)
|
240
|
+
|
241
|
+
Hirb.enable
|
242
|
+
Hirb.disable
|
243
|
+
|
244
|
+
expect(Hirb::View.enabled?).to eq(false)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "capture_and_render" do
|
248
|
+
string = "no waaaay"
|
249
|
+
|
250
|
+
# Hirb::View.render_method.expects(:call).with(string)
|
251
|
+
allow(Hirb::View.render_method).to receive(:call).with(string)
|
252
|
+
Hirb::View.capture_and_render { print string }
|
253
|
+
end
|
254
|
+
|
255
|
+
xit "state is toggled by toggle_pager" do
|
256
|
+
# FIXME: 2021-02-14 - This causes other specs to fail
|
257
|
+
|
258
|
+
previous_state = Hirb::View.config[:pager]
|
259
|
+
|
260
|
+
Hirb::View.toggle_pager
|
261
|
+
|
262
|
+
expect(Hirb::View.config[:pager]).not_to eq(previous_state)
|
263
|
+
end
|
264
|
+
|
265
|
+
xit "state is toggled by toggle_formatter" do
|
266
|
+
# FIXME: 2021-02-14 - This causes other specs to fail
|
267
|
+
|
268
|
+
Hirb.enable
|
269
|
+
|
270
|
+
previous_state = Hirb::View.config[:formatter]
|
271
|
+
|
272
|
+
Hirb::View.toggle_formatter
|
273
|
+
|
274
|
+
expect(Hirb::View.config[:formatter]).not_to eq(previous_state)
|
275
|
+
end
|
276
|
+
end
|
data/spec/views_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "hirber"
|
3
|
+
|
4
|
+
RSpec.describe "activerecord table" do
|
5
|
+
before do
|
6
|
+
Hirb.enable
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
Hirb.disable
|
11
|
+
end
|
12
|
+
|
13
|
+
context "with no select" do
|
14
|
+
let(:pet) do
|
15
|
+
double(
|
16
|
+
name: "rufus",
|
17
|
+
age: 7,
|
18
|
+
attributes: { "name" => "rufus", "age" => 7 },
|
19
|
+
class: double(column_names: %w{age name}),
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "gets default options" do
|
24
|
+
expect(Hirb::Helpers::AutoTable.active_record__base_view(pet))
|
25
|
+
.to eq(fields: [:age, :name])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "with select" do
|
30
|
+
let(:pet) do
|
31
|
+
double(
|
32
|
+
name: "rufus",
|
33
|
+
age: 7,
|
34
|
+
attributes: { "name" => "rufus" },
|
35
|
+
class: double(column_names: %w{age name}),
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "gets default options" do
|
40
|
+
expect(Hirb::Helpers::AutoTable.active_record__base_view(pet))
|
41
|
+
.to eq(fields: [:name])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
RSpec.describe "mongoid table" do
|
47
|
+
let(:mongoid_stub) { double(class: double(fields: fields)) }
|
48
|
+
let(:fields) { {"_id" => "x0f0x", "name" => "blah"} }
|
49
|
+
|
50
|
+
it "only has one _id" do
|
51
|
+
expect(Hirb::Helpers::AutoTable.mongoid__document_view(mongoid_stub))
|
52
|
+
.to eq(fields: fields.keys.sort)
|
53
|
+
end
|
54
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "bacon"
|
2
|
+
require "bacon/bits"
|
3
|
+
require "mocha-on-bacon"
|
4
|
+
require "hirber"
|
5
|
+
|
5
6
|
include Hirb
|
6
7
|
|
7
8
|
module TestHelpers
|
8
|
-
# set these to avoid invoking stty multiple times which doubles
|
9
|
+
# set these to avoid invoking stty multiple times which doubles
|
10
|
+
# test suite running time
|
11
|
+
|
9
12
|
ENV["LINES"] = ENV["COLUMNS"] = "20"
|
13
|
+
|
10
14
|
def reset_terminal_size
|
11
15
|
ENV["LINES"] = ENV["COLUMNS"] = "20"
|
12
16
|
end
|
metadata
CHANGED
@@ -1,15 +1,44 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Horner
|
8
|
+
- Aleksander Długopolski
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
12
|
+
date: 2021-02-14 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '3.9'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '3.9'
|
13
42
|
- !ruby/object:Gem::Dependency
|
14
43
|
name: bacon
|
15
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -76,7 +105,7 @@ description: Hirb provides a mini view framework for console applications and us
|
|
76
105
|
offers a smart pager and a console menu. The smart pager only pages when the output
|
77
106
|
exceeds the current screen size. The menu is used in conjunction with tables to
|
78
107
|
offer two dimensional menus.
|
79
|
-
email:
|
108
|
+
email: ad@dotpro.org
|
80
109
|
executables: []
|
81
110
|
extensions: []
|
82
111
|
extra_rdoc_files:
|
@@ -122,6 +151,9 @@ files:
|
|
122
151
|
- lib/hirb/views/rails.rb
|
123
152
|
- lib/hirber.rb
|
124
153
|
- lib/ripl/hirb.rb
|
154
|
+
- spec/spec_helper.rb
|
155
|
+
- spec/view_spec.rb
|
156
|
+
- spec/views_spec.rb
|
125
157
|
- test/auto_table_test.rb
|
126
158
|
- test/console_test.rb
|
127
159
|
- test/dynamic_view_test.rb
|