Last active
September 25, 2015 22:58
-
-
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)
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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
set HEADLESS environment var so we can run the watir test Headless.ly (see headless gem)