karenina 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +1 -0
- data/bin/kspec +115 -0
- data/lib/karenina/book.rb +6 -2
- data/lib/karenina/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWI5ZmQ0MjNkZThjMmZkZjU1OTBmNTVjMjljMzM3MzFhYzU4NzZlNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDhlN2U1MzA4NjAzYzIwMTBmYjdhZWVjNGFkYTExZDE3Y2ZhNmNmZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDRiNDhkY2NkYTNkMGJmZDIyOGIxYzUyNzE1OTJjNzFjMDNlNWI5YmQ1MWFh
|
10
|
+
OTA3NWU5MmI5YzcwMDUyOTgxOGVkNzU4NDRhZTBhMmI1ZmQ2NTY1ZWVmODY5
|
11
|
+
YWQwNTI3ZmU1NzYxOWQzNGQ2ZTRjZmZiZTIzZjA4YWYzMjIxZTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTk1OGUwMmEzZDYzMzc1MTY5ZmYxMTE4YTRmZWNlYmUwMWRiZjJkMzNhMmVl
|
14
|
+
NmI1Y2Q0MDVhNjk0YTIxZjI3NDJhZjUxYTE4YTlmZDFmNTgyNmFhZGJhOThj
|
15
|
+
ZDE4Y2ExMmI2Zjc1MWFlNWVjZmFlMWE1OWEwY2U5N2JjN2RkMTc=
|
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
If you added up the time you spent waiting for rails to load before you could run your tests, you could have read a russian novel.
|
4
4
|
|
5
|
+
Karenina prints one line (and some context) of the Anna Karenina each time you run your tests, and keeps track of where you are, so you can read across multiple apps!
|
5
6
|
|
6
7
|
|
7
8
|
## Installation
|
data/bin/kspec
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'curses'
|
3
|
+
|
4
|
+
require 'stringio'
|
5
|
+
require 'rspec/core'
|
6
|
+
require File.expand_path('../../lib/karenina', __FILE__)
|
7
|
+
|
8
|
+
class Scroller
|
9
|
+
|
10
|
+
def initialize(stringio, height)
|
11
|
+
@io = stringio
|
12
|
+
@offset = 0
|
13
|
+
@height = 15
|
14
|
+
end
|
15
|
+
|
16
|
+
def num_lines
|
17
|
+
@io.rewind
|
18
|
+
@io.lines.map{|x|}.length
|
19
|
+
end
|
20
|
+
|
21
|
+
def up
|
22
|
+
@offset -= 1 unless @offset.zero?
|
23
|
+
end
|
24
|
+
|
25
|
+
def down
|
26
|
+
@offset += 1 unless @offset + @height > num_lines
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_str
|
30
|
+
lines = []
|
31
|
+
@io.rewind
|
32
|
+
@io.lines.collect{|l| lines << l}
|
33
|
+
bottom = @height+@offset < lines.length ? @height+@offset : lines.length
|
34
|
+
top = @offset
|
35
|
+
#output = "top: #{top}, bottom: #{bottom}, lines: #{num_lines}"
|
36
|
+
lines[top..bottom].join("\n")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
class SpecRunner
|
42
|
+
def initialize(collector)
|
43
|
+
@tests_output = collector || StringIO.new
|
44
|
+
end
|
45
|
+
def run
|
46
|
+
RSpec::Core::Runner.run(["./"], @tests_output, @tests_output)
|
47
|
+
end
|
48
|
+
def output
|
49
|
+
if @test_output.kind_of? (StringIO)
|
50
|
+
@tests_output.rewind
|
51
|
+
@tests_output.read
|
52
|
+
else
|
53
|
+
@tests_output.to_str
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def init_screen
|
60
|
+
|
61
|
+
Curses.noecho # do not show typed keys
|
62
|
+
Curses.timeout = 0 # do not block and wait for input
|
63
|
+
Curses.init_screen
|
64
|
+
Curses.stdscr.keypad(true) # enable arrow keys
|
65
|
+
begin
|
66
|
+
yield
|
67
|
+
ensure
|
68
|
+
Curses.close_screen
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def write(line, column, text)
|
73
|
+
Curses.setpos(line, column)
|
74
|
+
Curses.addstr(text);
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
def novel_display(text)
|
79
|
+
write(0,0, text)
|
80
|
+
end
|
81
|
+
|
82
|
+
def warning_display(text)
|
83
|
+
write(12,0, text)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def test_display(text)
|
88
|
+
write(14q,0, text)
|
89
|
+
end
|
90
|
+
|
91
|
+
init_screen do
|
92
|
+
|
93
|
+
karenina = Karenina::Reader.new
|
94
|
+
collector = StringIO.new
|
95
|
+
spec_runner = SpecRunner.new(collector)
|
96
|
+
scroller = Scroller.new(collector, Curses.cols)
|
97
|
+
threads = []
|
98
|
+
threads << Thread.new {spec_runner.run}
|
99
|
+
|
100
|
+
loop do
|
101
|
+
Curses.clear
|
102
|
+
novel_display(karenina)
|
103
|
+
warning_display('press q to exit, not ctrl-c it will mess things up')
|
104
|
+
test_display(scroller)
|
105
|
+
case Curses.getch
|
106
|
+
when Curses::Key::UP then scroller.up
|
107
|
+
when Curses::Key::DOWN then scroller.down
|
108
|
+
when ?j then karenina.down
|
109
|
+
when ?k then karenina.up
|
110
|
+
when ?q then break
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
data/lib/karenina/book.rb
CHANGED
@@ -41,7 +41,7 @@ module Karenina
|
|
41
41
|
def print
|
42
42
|
output = []
|
43
43
|
skip_blank
|
44
|
-
|
44
|
+
printable_line_nums.each {|line|
|
45
45
|
text = @lines[line].to_s.chomp
|
46
46
|
if line == current_line_num
|
47
47
|
output << "#{bold_line(text)}"
|
@@ -54,13 +54,17 @@ module Karenina
|
|
54
54
|
|
55
55
|
def to_str
|
56
56
|
output = []
|
57
|
-
|
57
|
+
printable_line_nums.each {|line|
|
58
58
|
text = @lines[line].to_s.chomp
|
59
59
|
output << "#{text}"
|
60
60
|
}
|
61
61
|
output.join("\n") + "\n"
|
62
62
|
end
|
63
63
|
|
64
|
+
def printable_line_nums
|
65
|
+
first_line_num.upto(last_line_num)
|
66
|
+
end
|
67
|
+
|
64
68
|
def bold_line(text)
|
65
69
|
output = []
|
66
70
|
separator = ""
|
data/lib/karenina/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: karenina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Graeme Worthy
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description: read a line of anna karenina each time you run your tests
|
56
56
|
email:
|
57
57
|
- graeme@workben.ch
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- kspec
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -64,6 +65,7 @@ files:
|
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
68
|
+
- bin/kspec
|
67
69
|
- karenina.gemspec
|
68
70
|
- lib/karenina.rb
|
69
71
|
- lib/karenina/book.rb
|