tests using fish-spec

pull/2/head
Bruno Pinto 10 years ago
parent 13051d0168
commit 7c9d660f2c

@ -0,0 +1,24 @@
function expect
set -l expected $argv[1..-3]
set -l comparison $argv[-2]
set -l actual $argv[-1]
switch $comparison
case 'to_equal'
if test "$expected" = "$actual"
emit assertion_success
else
emit assertion_failure "Expected: \"$expected\""\n" Actual: \"$actual\""
end
case 'to_include'
set -l item $actual
set -l list $expected
if contains -- "$item" $list
emit assertion_success
else
emit assertion_failure "Expected \"$list\" to include \"$item\""
end
end
end

@ -0,0 +1,11 @@
function run_spec -a test
eval $test
end
function run_spec._.results.assertion_success -e assertion_success
printf '.'
end
function run_spec._.results.assertion_failure -e assertion_failure
echo $argv
end

@ -0,0 +1,17 @@
function run_specs
# Run each describe function
for describe in (functions -n | grep describe_)
eval $describe
end
# Run before all block
eval "before_all"
# Run tests
for test in (functions -n | grep it_)
run_spec $test
end
# Run after all block
eval "after_all"
end

@ -1,80 +1,71 @@
function suite_oh-my-fish
function setup
function describe_oh_my_fish
function before_all
set -g fish_custom_bak $fish_custom
set -g fish_function_path_bak $fish_function_path
set -g fish_plugins_bak $fish_plugins
end
function teardown
function after_all
set fish_custom $fish_custom_bak
set fish_function_path $fish_function_path_bak
set fish_plugins $fish_plugins_bak
end
#
# tests
#
function test_default_custom_folder
function it_has_a_default_custom_folder
set -e fish_custom
load_oh_my_fish
assert_equal ~/.oh-my-fish/custom $fish_custom
expect $fish_custom to_equal "$HOME/.oh-my-fish/custom"
end
function test_custom_folder
function it_allows_the_custom_folder_location_to_be_customized
set fish_custom /tmp
load_oh_my_fish
assert_equal /tmp $fish_custom
expect $fish_custom to_equal '/tmp'
end
function test_load_custom_files
function it_loads_all_custom_files
set fish_custom /tmp
echo 'set -gx TEST_LOAD_CUSTOM_FILE test_load' > $fish_custom/test.load
echo 'set -gx TEST_LOAD_CUSTOM_FILE file_loaded' > $fish_custom/test.load
load_oh_my_fish
assert_equal test_load $TEST_LOAD_CUSTOM_FILE
expect $TEST_LOAD_CUSTOM_FILE to_equal 'file_loaded'
end
function test_oh_my_fish_functions
function it_loads_all_oh_my_fish_functions
remove_from_array "$fish_path/functions/" fish_function_path
load_oh_my_fish
assert_includes $fish_path/functions/ $fish_function_path
expect $fish_function_path to_include $fish_path/functions/
end
function test_oh_my_fish_plugins
function it_loads_all_selected_plugins
remove_from_array "$fish_path/plugins/z" fish_function_path
set fish_plugins z
set fish_plugins bak z
load_oh_my_fish
assert_includes $fish_path/plugins/z $fish_function_path
expect $fish_function_path to_include $fish_path/plugins/bak and
expect $fish_function_path to_include $fish_path/plugins/z
end
function test_oh_my_fish_themes
function it_loads_the_selected_theme
remove_from_array "$fish_path/themes/l" fish_function_path
set fish_theme l
load_oh_my_fish
assert_includes $fish_path/themes/l $fish_function_path
expect $fish_function_path to_include $fish_path/themes/l
end
end
#
# helper functions
#
function load_oh_my_fish
. $fish_path/oh-my-fish.fish
end
function load_oh_my_fish
. $fish_path/oh-my-fish.fish
end
function remove_from_array
set -l element $argv[1]
function remove_from_array
set -l element $argv[1]
for i in (seq (count $$argv[2]))
if test $$argv[2][$i] = $element
set -e $argv[2][$i]
break
end
for i in (seq (count $$argv[2]))
if test $$argv[2][$i] = $element
set -e $argv[2][$i]
break
end
end
end
if not set -q tank_running
source (dirname (status -f))/helper.fish
tank_run
end
import plugins/fish-spec

Loading…
Cancel
Save