Skip to content

Commit

Permalink
Add sspec_ify script and sspec_ify a few tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
noahgibbs committed Nov 15, 2023
1 parent 88189e5 commit fa31fc7
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 400 deletions.
36 changes: 36 additions & 0 deletions bin/sspec_ify.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env ruby

# Want to use this script on a whole subtree? Find is your friend.
# Something like:
# find . -name "*.rb" -exec ../../../bin/sspec_ify.rb --git \{\} \;

# If the script gets the --git param, it will git add and git rm the file,
# not just modify and delete it.
use_git = ARGV.delete("--git")

if ARGV.size != 1
raise "Please specify a single .rb file to sspec-ify."
end

old_file = ARGV[0]

file_text = File.read old_file
indented_text = file_text.split("\n").map { |s| " " + s }.join("\n")

sspec_text = <<SSPEC
---
----------- app code
#{indented_text}
----------- test code
assert true, "Assert that test code runs at all."
SSPEC

new_file = old_file.gsub(/\.rb\Z/, ".sspec")
File.write(new_file, sspec_text)
File.unlink old_file

if use_git
system "git rm #{old_file}" || raise("Can't git rm #{old_file.inspect}!")
system "git add #{new_file}" || raise("Can't git add #{new_file.inspect}!")
end

6 changes: 6 additions & 0 deletions cases/legacy_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ These are Shoes examples, taken from a wide variety of sources. In general, we t

Shoes-Spec originated with Scarpe, so no pre-Scarpe legacy applications have test code, only .rb Shoes apps.

## Pass Rate

What % of these are passing is going to drift in odd ways over time. We would like to add more test code
to check functionality. But of course, adding test code will result in more failures, including for
display services that had previously been passing.

55 changes: 0 additions & 55 deletions cases/legacy_examples/misc/speedometer_app.rb

This file was deleted.

58 changes: 58 additions & 0 deletions cases/legacy_examples/misc/speedometer_app.sspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
----------- app code
# Source: https://www.hanselman.com/blog/the-weekly-source-code-29-ruby-and-shoes-and-the-first-ruby-virus

class Speedometer < Shoes::Widget
attr_accessor :range, :tick, :position
def initialize opts = {}
@range = opts[:range] || 200
@tick = opts[:tick] || 10
@position = opts[:position] || 0
@cx, @cy = self.left + 110, self.top + 100

nostroke
rect :top => self.top, :left => self.left,
:width => 220, :height => 200
nofill
stroke white
oval :left => @cx - 50, :top => @cy - 50, :radius => 100
(ticks + 1).times do |i|
radial_line 225 + ((270.0 / ticks) * i), 70..80
radial_line 225 + ((270.0 / ticks) * i), 45..49
end
strokewidth 2
oval :left => @cx - 70, :top => @cy - 70, :radius => 140
stroke lightgreen
oval :left => @cx - 5, :top => @cy - 5, :radius => 10
@needle = radial_line 225 + ((270.0 / @range) * @position), 0..90
end
def ticks; @range / @tick end
def radial_line deg, r
pos = ((deg / 360.0) * (2.0 * Math::PI)) - (Math::PI / 2.0)
line (Math.cos(pos) * r.begin) + @cx, (Math.sin(pos) * r.begin) + @cy,
(Math.cos(pos) * r.end) + @cx, (Math.sin(pos) * r.end) + @cy
end
def position= pos
@position = pos
@needle.remove
append do
@needle = radial_line 225 + ((270.0 / @range) * @position), 0..90
end
end
end

Shoes.app do
stack do
para "Enter a number between 0 and 100"
flow do
@p = edit_line
button "OK" do
@s.position = @p.text.to_i
end
end

@s = speedometer :range => 100, :ticks => 10
end
end
----------- test code
assert true, "Assert that test code runs at all."
Loading

0 comments on commit fa31fc7

Please sign in to comment.