-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sspec_ify script and sspec_ify a few tests.
- Loading branch information
Showing
14 changed files
with
481 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
Oops, something went wrong.