Skip to content

Instantly share code, notes, and snippets.

@olore
Last active September 25, 2015 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olore/998921 to your computer and use it in GitHub Desktop.
Save olore/998921 to your computer and use it in GitHub Desktop.
Ruby vim script for running test unit (with def test_whatever or test "whatever" do or it "whatever" do)
#!/usr/bin/env ruby
filename = ARGV[0]
line_number = ARGV[1].to_i
path = File.expand_path(filename)
export_for_watir = path =~ /watir/ ? "export HEADLESS=1; " : ""
lines = File.read(filename).split(/\n/)
(line_number - 1).downto(0) do |i|
if lines[i] =~ /\s*def (test\S*)/
cmd = %{#{export_for_watir}ruby -Ilib:test "#{filename}" -n "#{$1}"}
elsif lines[i] =~ /\s*test "(.*)" do/
test_name = $1.gsub(' ', '_')
cmd = %{#{export_for_watir}ruby -Ilib:test "#{filename}" -n test_#{test_name}}
elsif lines[i] =~ /\s*it "(.*)" do/
test_name = $1
cmd = %{#{export_for_watir}rspec -Ilib:spec "#{filename}" --example "#{test_name}"}
end
if cmd
puts cmd
system cmd
exit
end
end
@olore
Copy link
Author

olore commented May 4, 2012

set HEADLESS environment var so we can run the watir test Headless.ly (see headless gem)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment