From d66a0af8c2654519277d4857415275fde207ac44 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Fri, 22 Jan 2016 16:29:13 +0200 Subject: [PATCH 01/18] Added Gemfile with nokogiri dependency --- .gitignore | 1 + Gemfile | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 Gemfile diff --git a/.gitignore b/.gitignore index 1377554..b782f12 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *.swp +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f5e3d50 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'nokogiri', '1.6.7.2' From 1580ffd981a98c292342ed7d4c3ab2813c86988a Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Fri, 22 Jan 2016 16:41:24 +0200 Subject: [PATCH 02/18] A tiny changes in readme about installation --- README.md | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 76b483b..e5a43a9 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,27 @@ HISTORY INSTALL ------- - * Requires: gem install hpricot - * Install with pathogen: clone/submodule into vim/bundle - * **rbenv** users will need to install hpricot using system ruby `RBENV_VERSION=system sudo gem install hpricot` + +# External dependencies + +Because of ending of `hpricot` gem maintenance was made decision about moving into `nokogiri`. So this gem is required for `vim-rspec` work. +You may install it manually by run `gem install nokogiri` or go into plugin folder and run `bundle`. + +# VIM plugin managers + +## Pathogen +Install with pathogen: clone/submodule into vim/bundle + +## VIM-PLUG +Added into `~/.vimrc` the following line: + +``` +call plug#begin('~/.vim/plugged') + +Plug 'alterego-labs/vim-rspec' + +call plug#end() +``` USAGE ----- From 85cb2f8755b76e155f0b5d37988ab3fc828a9ebb Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Fri, 22 Jan 2016 17:23:30 +0200 Subject: [PATCH 03/18] A tiny function arragements Check nokogiry now throws exception. --- plugin/vim-rspec.vim | 108 ++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 58 deletions(-) diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index 4a5b950..ebddade 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -15,73 +15,16 @@ " * g:RspecOpts :: Opts to send to rspec call " * g:RspecSplitHorizontal :: Set to 0 to cause Vertical split (default:1) -let s:hpricot_cmd = "" -let s:hpricot = 0 let s:helper_dir = expand(":h") if !exists("g:RspecKeymap") let g:RspecKeymap=1 end -function! s:find_hpricot() - return system("( gem search -i hpricot &> /dev/null && echo true ) - \ || ( dpkg-query -Wf'${db:Status-abbrev}' ruby-hpricot 2>/dev/null - \ | grep -q '^i' && echo true ) - \ || echo false") -endfunction - -function! s:error_msg(msg) - echohl ErrorMsg - echo a:msg - echohl None -endfunction - -function! s:notice_msg(msg) - echohl MoreMsg - echo a:msg - echohl None -endfunction - -function! s:fetch(varname, default) - if exists("g:".a:varname) - return eval("g:".a:varname) - else - return a:default - endif -endfunction - -function! s:createOutputWin() - if !exists("g:RspecSplitHorizontal") - let g:RspecSplitHorizontal=1 - endif - - let splitLocation = "botright " - let splitSize = 15 - - if bufexists('RSpecOutput') - silent! bw! RSpecOutput - end - - if g:RspecSplitHorizontal == 1 - silent! exec splitLocation . ' ' . splitSize . ' new' - else - silent! exec splitLocation . ' ' . splitSize . ' vnew' - end - silent! exec "edit RSpecOutput" -endfunction - function! s:RunSpecMain(type) let l:bufn = expand("%:p") let s:SpecFile = l:bufn - if len(s:hpricot_cmd)<1 - let s:hpricot_cmd = s:find_hpricot() - let s:hpricot = match(s:hpricot_cmd,'true')>=0 - end - - if !s:hpricot - call s:error_msg("You need the hpricot gem to run this script.") - return - end + call s:check_nokogiri() " find the installed rspec command let l:default_cmd = "" @@ -176,6 +119,21 @@ function! s:RunSpecMain(type) endfunction +function! s:createOutputWin() + let isSplitHorizontal = s:fetch("RspecSplitHorizontal", 1) + let splitDirCommand = isSplitHorizontal == 1 ? 'new' : 'vnew' + + let splitLocation = "botright " + let splitSize = 15 + + if bufexists('RSpecOutput') + silent! bw! RSpecOutput + end + + silent! exec splitLocation . ' ' . splitSize . ' ' . splitDirCommand + silent! exec "edit RSpecOutput" +endfunction + function! s:FindWindowByBufferName(buffername) let l:windowNumberToBufnameList = map(range(1, winnr('$')), '[v:val, bufname(winbufnr(v:val))]') let l:arrayIndex = match(l:windowNumberToBufnameList, a:buffername) @@ -211,6 +169,40 @@ function! s:TryToOpen() call cursor(l:tokens[1],1) endfunction +"============== +" Checks `nokogiri` gem availability +function! s:check_nokogiri() + let s:nokogiri = s:find_nokogiri() + let s:nokogiri = match(s:nokogiri,'true') >= 0 + if !s:nokogiri + throw("You need the `nokogiri` gem to run this script.") + end +endfunction + +function! s:find_nokogiri() + return system("( gem search -i nokogiri &> /dev/null && echo true )") +endfunction + +function! s:error_msg(msg) + echohl ErrorMsg + echo a:msg + echohl None +endfunction + +function! s:notice_msg(msg) + echohl MoreMsg + echo a:msg + echohl None +endfunction + +function! s:fetch(varname, default) + if exists("g:".a:varname) + return eval("g:".a:varname) + else + return a:default + endif +endfunction + function! RunSpec() call s:RunSpecMain("file") endfunction From a7a90183ac19ca8bc5150d93516f2bcfcca86c7a Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Fri, 22 Jan 2016 17:58:00 +0200 Subject: [PATCH 04/18] Move some function into separate file Created helpers.vim --- plugin/sources/helpers.vim | 34 ++++++++++++++++++ plugin/vim-rspec.vim | 72 +++++++++++--------------------------- 2 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 plugin/sources/helpers.vim diff --git a/plugin/sources/helpers.vim b/plugin/sources/helpers.vim new file mode 100644 index 0000000..668fa00 --- /dev/null +++ b/plugin/sources/helpers.vim @@ -0,0 +1,34 @@ +"============== +" Checks `nokogiri` gem availability +function! g:CheckNokogiri() + let s:nokogiri = s:find_nokogiri() + let s:nokogiri = match(s:nokogiri,'true') >= 0 + if !s:nokogiri + throw("You need the `nokogiri` gem to run this script.") + end +endfunction + +function! s:find_nokogiri() + return system("( gem search -i nokogiri &> /dev/null && echo true )") +endfunction + +function! g:ErrorMsg(msg) + echohl ErrorMsg + echo a:msg + echohl None +endfunction + +function! g:NoticeMsg(msg) + echohl MoreMsg + echo a:msg + echohl None +endfunction + +function! g:FetchVar(varname, default) + if exists("g:".a:varname) + return eval("g:".a:varname) + else + return a:default + endif +endfunction + diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index ebddade..ea76cae 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -20,11 +20,13 @@ if !exists("g:RspecKeymap") let g:RspecKeymap=1 end +runtime! plugin/sources/helpers.vim + function! s:RunSpecMain(type) let l:bufn = expand("%:p") let s:SpecFile = l:bufn - call s:check_nokogiri() + call g:CheckNokogiri() " find the installed rspec command let l:default_cmd = "" @@ -35,42 +37,42 @@ function! s:RunSpecMain(type) end " filter - let l:filter = "ruby ". s:fetch("RspecRBPath", s:helper_dir."/vim-rspec.rb") + let l:filter = "ruby ". g:FetchVar("RspecRBPath", s:helper_dir."/vim-rspec.rb") " run just the current file if a:type=="file" if match(l:bufn,'_spec.rb')>=0 - call s:notice_msg("Running " . s:SpecFile . "...") - let l:spec_bin = s:fetch("RspecBin",l:default_cmd) - let l:spec_opts = s:fetch("RspecOpts", "") + call g:NoticeMsg("Running " . s:SpecFile . "...") + let l:spec_bin = g:FetchVar("RspecBin",l:default_cmd) + let l:spec_opts = g:FetchVar("RspecOpts", "") let l:spec = l:spec_bin . " " . l:spec_opts . " -f h " . l:bufn else - call s:error_msg("Seems ".l:bufn." is not a *_spec.rb file") + call g:ErrorMsg("Seems ".l:bufn." is not a *_spec.rb file") return end elseif a:type=="line" if match(l:bufn,'_spec.rb')>=0 let l:current_line = line('.') - call s:notice_msg("Running Line " . l:current_line . " on " . s:SpecFile . " ") - let l:spec_bin = s:fetch("RspecBin",l:default_cmd) - let l:spec_opts = s:fetch("RspecOpts", "") + call g:NoticeMsg("Running Line " . l:current_line . " on " . s:SpecFile . " ") + let l:spec_bin = g:FetchVar("RspecBin",l:default_cmd) + let l:spec_opts = g:FetchVar("RspecOpts", "") let l:spec = l:spec_bin . " " . l:spec_opts . " -l " . l:current_line . " -f h " . l:bufn else - call s:error_msg("Seems ".l:bufn." is not a *_spec.rb file") + call g:ErrorMsg("Seems ".l:bufn." is not a *_spec.rb file") return end elseif a:type=="rerun" if exists("s:spec") let l:spec = s:spec else - call s:error_msg("No rspec run to repeat") + call g:ErrorMsg("No rspec run to repeat") return end else let l:dir = expand("%:p:h") if isdirectory(l:dir."/spec")>0 - call s:notice_msg("Running spec on the spec directory ...") + call g:NoticeMsg("Running spec on the spec directory ...") else " try to find a spec directory on the current path let l:tokens = split(l:dir,"/") @@ -84,17 +86,17 @@ function! s:RunSpecMain(type) end endfor if len(l:dir)>0 - call s:notice_msg("Running spec with on the spec directory found (".l:dir.") ...") + call g:NoticeMsg("Running spec with on the spec directory found (".l:dir.") ...") else - call s:error_msg("No ".l:dir."/spec directory found") + call g:ErrorMsg("No ".l:dir."/spec directory found") return end end if isdirectory(l:dir)<0 - call s:error_msg("Could not find the ".l:dir." directory.") + call g:ErrorMsg("Could not find the ".l:dir." directory.") return end - let l:spec = s:fetch("RspecBin", l:default_cmd) . s:fetch("RspecOpts", "") + let l:spec = g:FetchVar("RspecBin", l:default_cmd) . g:FetchVar("RspecOpts", "") let l:spec = l:spec . " -f h " . l:dir . " -p **/*_spec.rb" end let s:spec = l:spec @@ -120,7 +122,7 @@ function! s:RunSpecMain(type) endfunction function! s:createOutputWin() - let isSplitHorizontal = s:fetch("RspecSplitHorizontal", 1) + let isSplitHorizontal = g:FetchVar("RspecSplitHorizontal", 1) let splitDirCommand = isSplitHorizontal == 1 ? 'new' : 'vnew' let splitLocation = "botright " @@ -155,7 +157,7 @@ function! s:TryToOpen() call search("_spec","bcW") let l:line = getline(".") if match(l:line,'^ .*_spec.rb')<0 - call s:error_msg("No spec file found.") + call g:ErrorMsg("No spec file found.") return end let l:tokens = split(l:line,":") @@ -169,40 +171,6 @@ function! s:TryToOpen() call cursor(l:tokens[1],1) endfunction -"============== -" Checks `nokogiri` gem availability -function! s:check_nokogiri() - let s:nokogiri = s:find_nokogiri() - let s:nokogiri = match(s:nokogiri,'true') >= 0 - if !s:nokogiri - throw("You need the `nokogiri` gem to run this script.") - end -endfunction - -function! s:find_nokogiri() - return system("( gem search -i nokogiri &> /dev/null && echo true )") -endfunction - -function! s:error_msg(msg) - echohl ErrorMsg - echo a:msg - echohl None -endfunction - -function! s:notice_msg(msg) - echohl MoreMsg - echo a:msg - echohl None -endfunction - -function! s:fetch(varname, default) - if exists("g:".a:varname) - return eval("g:".a:varname) - else - return a:default - endif -endfunction - function! RunSpec() call s:RunSpecMain("file") endfunction From 54804bddd2c5933294900fd4e022039d667d65e2 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Fri, 22 Jan 2016 18:07:08 +0200 Subject: [PATCH 05/18] Extracted window commands into file --- plugin/sources/win_cmd.vim | 50 ++++++++++++++++++++++++++++++++++ plugin/vim-rspec.vim | 55 +++----------------------------------- 2 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 plugin/sources/win_cmd.vim diff --git a/plugin/sources/win_cmd.vim b/plugin/sources/win_cmd.vim new file mode 100644 index 0000000..d20f973 --- /dev/null +++ b/plugin/sources/win_cmd.vim @@ -0,0 +1,50 @@ +function! g:CreateOutputWin() + let isSplitHorizontal = g:FetchVar("RspecSplitHorizontal", 1) + let splitDirCommand = isSplitHorizontal == 1 ? 'new' : 'vnew' + + let splitLocation = "botright " + let splitSize = 15 + + if bufexists('RSpecOutput') + silent! bw! RSpecOutput + end + + silent! exec splitLocation . ' ' . splitSize . ' ' . splitDirCommand + silent! exec "edit RSpecOutput" +endfunction + +function! s:FindWindowByBufferName(buffername) + let l:windowNumberToBufnameList = map(range(1, winnr('$')), '[v:val, bufname(winbufnr(v:val))]') + let l:arrayIndex = match(l:windowNumberToBufnameList, a:buffername) + let l:windowNumber = windowNumberToBufnameList[l:arrayIndex][0] + return l:windowNumber +endfunction + +function! s:SwitchToWindowNumber(number) + exe a:number . "wincmd w" +endfunction + +function! s:SwitchToWindowByName(buffername) + let l:windowNumber = s:FindWindowByBufferName(a:buffername) + call s:SwitchToWindowNumber(l:windowNumber) +endfunction + +function! g:TryToOpen() + " Search up to find '*_spec.rb' + call search("_spec","bcW") + let l:line = getline(".") + if match(l:line,'^ .*_spec.rb')<0 + call g:ErrorMsg("No spec file found.") + return + end + let l:tokens = split(l:line,":") + + " move back to the other window, if available + call s:SwitchToWindowByName(s:SpecFile) + + " open the file in question (either in the split) + " that was already open, or in the current win + exec "e ".substitute(l:tokens[0],'/^\s\+',"","") + call cursor(l:tokens[1],1) +endfunction + diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index ea76cae..440d068 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -16,11 +16,13 @@ " * g:RspecSplitHorizontal :: Set to 0 to cause Vertical split (default:1) let s:helper_dir = expand(":h") + if !exists("g:RspecKeymap") let g:RspecKeymap=1 end runtime! plugin/sources/helpers.vim +runtime! plugin/sources/win_cmd.vim function! s:RunSpecMain(type) let l:bufn = expand("%:p") @@ -105,7 +107,7 @@ function! s:RunSpecMain(type) let s:cmd = l:spec." | ".l:filter "put the result on a new buffer - call s:createOutputWin() + call g:CreateOutputWin() setl buftype=nofile silent exec "r! ".s:cmd setl syntax=vim-rspec @@ -118,57 +120,6 @@ function! s:RunSpecMain(type) setl foldexpr=getline(v:lnum)=~'^\+' setl foldtext=\"+--\ \".string(v:foldend-v:foldstart+1).\"\ passed\ \" call cursor(1,1) - -endfunction - -function! s:createOutputWin() - let isSplitHorizontal = g:FetchVar("RspecSplitHorizontal", 1) - let splitDirCommand = isSplitHorizontal == 1 ? 'new' : 'vnew' - - let splitLocation = "botright " - let splitSize = 15 - - if bufexists('RSpecOutput') - silent! bw! RSpecOutput - end - - silent! exec splitLocation . ' ' . splitSize . ' ' . splitDirCommand - silent! exec "edit RSpecOutput" -endfunction - -function! s:FindWindowByBufferName(buffername) - let l:windowNumberToBufnameList = map(range(1, winnr('$')), '[v:val, bufname(winbufnr(v:val))]') - let l:arrayIndex = match(l:windowNumberToBufnameList, a:buffername) - let l:windowNumber = windowNumberToBufnameList[l:arrayIndex][0] - return l:windowNumber -endfunction - -function! s:SwitchToWindowNumber(number) - exe a:number . "wincmd w" -endfunction - -function! s:SwitchToWindowByName(buffername) - let l:windowNumber = s:FindWindowByBufferName(a:buffername) - call s:SwitchToWindowNumber(l:windowNumber) -endfunction - -function! s:TryToOpen() - " Search up to find '*_spec.rb' - call search("_spec","bcW") - let l:line = getline(".") - if match(l:line,'^ .*_spec.rb')<0 - call g:ErrorMsg("No spec file found.") - return - end - let l:tokens = split(l:line,":") - - " move back to the other window, if available - call s:SwitchToWindowByName(s:SpecFile) - - " open the file in question (either in the split) - " that was already open, or in the current win - exec "e ".substitute(l:tokens[0],'/^\s\+',"","") - call cursor(l:tokens[1],1) endfunction function! RunSpec() From dbe5a0c421fedd3415ac4f6dc726b8bad87d6be3 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Sat, 23 Jan 2016 21:39:10 +0200 Subject: [PATCH 06/18] Refactored helpers definitions and usages Use namespaced functions names --- plugin/sources/helpers.vim | 34 ---------------- plugin/vim-rspec.vim | 45 +++++++++------------ plugin/vim_rspec/helpers.vim | 49 +++++++++++++++++++++++ plugin/{sources => vim_rspec}/win_cmd.vim | 0 4 files changed, 69 insertions(+), 59 deletions(-) delete mode 100644 plugin/sources/helpers.vim create mode 100644 plugin/vim_rspec/helpers.vim rename plugin/{sources => vim_rspec}/win_cmd.vim (100%) diff --git a/plugin/sources/helpers.vim b/plugin/sources/helpers.vim deleted file mode 100644 index 668fa00..0000000 --- a/plugin/sources/helpers.vim +++ /dev/null @@ -1,34 +0,0 @@ -"============== -" Checks `nokogiri` gem availability -function! g:CheckNokogiri() - let s:nokogiri = s:find_nokogiri() - let s:nokogiri = match(s:nokogiri,'true') >= 0 - if !s:nokogiri - throw("You need the `nokogiri` gem to run this script.") - end -endfunction - -function! s:find_nokogiri() - return system("( gem search -i nokogiri &> /dev/null && echo true )") -endfunction - -function! g:ErrorMsg(msg) - echohl ErrorMsg - echo a:msg - echohl None -endfunction - -function! g:NoticeMsg(msg) - echohl MoreMsg - echo a:msg - echohl None -endfunction - -function! g:FetchVar(varname, default) - if exists("g:".a:varname) - return eval("g:".a:varname) - else - return a:default - endif -endfunction - diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index 440d068..733d1dc 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -15,66 +15,61 @@ " * g:RspecOpts :: Opts to send to rspec call " * g:RspecSplitHorizontal :: Set to 0 to cause Vertical split (default:1) -let s:helper_dir = expand(":h") +let s:plugin_dir = expand(":h") if !exists("g:RspecKeymap") let g:RspecKeymap=1 end -runtime! plugin/sources/helpers.vim -runtime! plugin/sources/win_cmd.vim +execute "source " . s:plugin_dir . "/vim_rspec/helpers.vim" +execute "source " . s:plugin_dir . "/vim_rspec/win_cmd.vim" function! s:RunSpecMain(type) let l:bufn = expand("%:p") let s:SpecFile = l:bufn - call g:CheckNokogiri() + call vim_rspec#helpers#check_nokogiri() " find the installed rspec command - let l:default_cmd = "" - if executable("spec")==1 - let l:default_cmd = "spec" - elseif executable("rspec")==1 - let l:default_cmd = "rspec" - end + let l:default_cmd = vim_rspec#helpers#find_rspec_executable() " filter - let l:filter = "ruby ". g:FetchVar("RspecRBPath", s:helper_dir."/vim-rspec.rb") + let l:filter = vim_rspec#helpers#build_filter_command(s:plugin_dir) " run just the current file if a:type=="file" if match(l:bufn,'_spec.rb')>=0 - call g:NoticeMsg("Running " . s:SpecFile . "...") - let l:spec_bin = g:FetchVar("RspecBin",l:default_cmd) - let l:spec_opts = g:FetchVar("RspecOpts", "") + call vim_rspec#helpers#notice_msg("Running " . s:SpecFile . "...") + let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin",l:default_cmd) + let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") let l:spec = l:spec_bin . " " . l:spec_opts . " -f h " . l:bufn else - call g:ErrorMsg("Seems ".l:bufn." is not a *_spec.rb file") + call vim_rspec#helpers#error_msg("Seems ".l:bufn." is not a *_spec.rb file") return end elseif a:type=="line" if match(l:bufn,'_spec.rb')>=0 let l:current_line = line('.') - call g:NoticeMsg("Running Line " . l:current_line . " on " . s:SpecFile . " ") - let l:spec_bin = g:FetchVar("RspecBin",l:default_cmd) - let l:spec_opts = g:FetchVar("RspecOpts", "") + call vim_rspec#helpers#notice_msg("Running Line " . l:current_line . " on " . s:SpecFile . " ") + let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin",l:default_cmd) + let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") let l:spec = l:spec_bin . " " . l:spec_opts . " -l " . l:current_line . " -f h " . l:bufn else - call g:ErrorMsg("Seems ".l:bufn." is not a *_spec.rb file") + call vim_rspec#helpers#error_msg("Seems ".l:bufn." is not a *_spec.rb file") return end elseif a:type=="rerun" if exists("s:spec") let l:spec = s:spec else - call g:ErrorMsg("No rspec run to repeat") + call vim_rspec#helpers#error_msg("No rspec run to repeat") return end else let l:dir = expand("%:p:h") if isdirectory(l:dir."/spec")>0 - call g:NoticeMsg("Running spec on the spec directory ...") + call vim_rspec#helpers#notice_msg("Running spec on the spec directory ...") else " try to find a spec directory on the current path let l:tokens = split(l:dir,"/") @@ -88,17 +83,17 @@ function! s:RunSpecMain(type) end endfor if len(l:dir)>0 - call g:NoticeMsg("Running spec with on the spec directory found (".l:dir.") ...") + call vim_rspec#helpers#notice_msg("Running spec with on the spec directory found (".l:dir.") ...") else - call g:ErrorMsg("No ".l:dir."/spec directory found") + call vim_rspec#helpers#error_msg("No ".l:dir."/spec directory found") return end end if isdirectory(l:dir)<0 - call g:ErrorMsg("Could not find the ".l:dir." directory.") + call vim_rspec#helpers#error_msg("Could not find the ".l:dir." directory.") return end - let l:spec = g:FetchVar("RspecBin", l:default_cmd) . g:FetchVar("RspecOpts", "") + let l:spec = vim_rspec#helpers#fetch_var("RspecBin", l:default_cmd) . vim_rspec#helpers#fetch_var("RspecOpts", "") let l:spec = l:spec . " -f h " . l:dir . " -p **/*_spec.rb" end let s:spec = l:spec diff --git a/plugin/vim_rspec/helpers.vim b/plugin/vim_rspec/helpers.vim new file mode 100644 index 0000000..a1d57a8 --- /dev/null +++ b/plugin/vim_rspec/helpers.vim @@ -0,0 +1,49 @@ +function! vim_rspec#helpers#check_nokogiri() + let s:nokogiri = s:find_nokogiri() + let s:nokogiri = match(s:nokogiri,'true') >= 0 + if !s:nokogiri + throw("You need the `nokogiri` gem to run this script.") + end +endfunction + +function! vim_rspec#helpers#error_msg(msg) + echohl ErrorMsg + echo a:msg + echohl None +endfunction + +function! vim_rspec#helpers#notice_msg(msg) + echohl MoreMsg + echo a:msg + echohl None +endfunction + +function! vim_rspec#helpers#fetch_var(varname, default) + if exists("g:".a:varname) + return eval("g:".a:varname) + else + return a:default + endif +endfunction + +function! vim_rspec#helpers#find_rspec_executable() + if executable("spec") == 1 + return "spec" + elseif executable("rspec") == 1 + return "rspec" + end + return "" +endfunction + +function! vim_rspec#helpers#build_filter_command(plugin_dir) + let default_filter_cmd = a:plugin_dir . "/vim-rspec.rb" + let rb_path = vim_rspec#helpers#fetch_var("RspecRBPath", default_filter_cmd) + return "ruby" . db_path +endfunction + +"====== +" Local functions +"====== +function! s:find_nokogiri() + return system("( gem search -i nokogiri &> /dev/null && echo true )") +endfunction diff --git a/plugin/sources/win_cmd.vim b/plugin/vim_rspec/win_cmd.vim similarity index 100% rename from plugin/sources/win_cmd.vim rename to plugin/vim_rspec/win_cmd.vim From ea514358fa2d53146b1a1e379494de54e0172ca3 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Sat, 23 Jan 2016 21:43:31 +0200 Subject: [PATCH 07/18] Made win commands functions also namespaced --- plugin/vim-rspec.vim | 8 ++++---- plugin/vim_rspec/win_cmd.vim | 39 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index 733d1dc..ff350f4 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -102,13 +102,13 @@ function! s:RunSpecMain(type) let s:cmd = l:spec." | ".l:filter "put the result on a new buffer - call g:CreateOutputWin() + call vim_rspec#win_cmd#create_output_win() setl buftype=nofile silent exec "r! ".s:cmd setl syntax=vim-rspec - silent exec "nnoremap :call TryToOpen()" - silent exec 'nnoremap n /\/.*spec.*\::call TryToOpen()' - silent exec 'nnoremap N ?/\/.*spec.*\::call TryToOpen()' + silent exec "nnoremap :call vim_rspec#win_cmd#try_to_open()" + silent exec 'nnoremap n /\/.*spec.*\::call vim_rspec#win_cmd#try_to_open()' + silent exec 'nnoremap N ?/\/.*spec.*\::call vim_rspec#win_cmd#try_to_open()' silent exec "nnoremap q :q:wincmd p" setl nolist setl foldmethod=expr diff --git a/plugin/vim_rspec/win_cmd.vim b/plugin/vim_rspec/win_cmd.vim index d20f973..a0761c5 100644 --- a/plugin/vim_rspec/win_cmd.vim +++ b/plugin/vim_rspec/win_cmd.vim @@ -1,4 +1,4 @@ -function! g:CreateOutputWin() +function! vim_rspec#win_cmd#create_output_win() let isSplitHorizontal = g:FetchVar("RspecSplitHorizontal", 1) let splitDirCommand = isSplitHorizontal == 1 ? 'new' : 'vnew' @@ -13,23 +13,7 @@ function! g:CreateOutputWin() silent! exec "edit RSpecOutput" endfunction -function! s:FindWindowByBufferName(buffername) - let l:windowNumberToBufnameList = map(range(1, winnr('$')), '[v:val, bufname(winbufnr(v:val))]') - let l:arrayIndex = match(l:windowNumberToBufnameList, a:buffername) - let l:windowNumber = windowNumberToBufnameList[l:arrayIndex][0] - return l:windowNumber -endfunction - -function! s:SwitchToWindowNumber(number) - exe a:number . "wincmd w" -endfunction - -function! s:SwitchToWindowByName(buffername) - let l:windowNumber = s:FindWindowByBufferName(a:buffername) - call s:SwitchToWindowNumber(l:windowNumber) -endfunction - -function! g:TryToOpen() +function! vim_rspec#win_cmd#try_to_open() " Search up to find '*_spec.rb' call search("_spec","bcW") let l:line = getline(".") @@ -48,3 +32,22 @@ function! g:TryToOpen() call cursor(l:tokens[1],1) endfunction +"====== +" Local functions +"====== +function! s:FindWindowByBufferName(buffername) + let l:windowNumberToBufnameList = map(range(1, winnr('$')), '[v:val, bufname(winbufnr(v:val))]') + let l:arrayIndex = match(l:windowNumberToBufnameList, a:buffername) + let l:windowNumber = windowNumberToBufnameList[l:arrayIndex][0] + return l:windowNumber +endfunction + +function! s:SwitchToWindowNumber(number) + exe a:number . "wincmd w" +endfunction + +function! s:SwitchToWindowByName(buffername) + let l:windowNumber = s:FindWindowByBufferName(a:buffername) + call s:SwitchToWindowNumber(l:windowNumber) +endfunction + From a874392c51fa961aa95ea39229240205d3fc6e31 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Sat, 23 Jan 2016 21:48:01 +0200 Subject: [PATCH 08/18] Small rearragement Moved `filter` declaration into place that more tightly to the usage area. --- plugin/vim-rspec.vim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index ff350f4..e82f410 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -33,14 +33,11 @@ function! s:RunSpecMain(type) " find the installed rspec command let l:default_cmd = vim_rspec#helpers#find_rspec_executable() - " filter - let l:filter = vim_rspec#helpers#build_filter_command(s:plugin_dir) - " run just the current file if a:type=="file" if match(l:bufn,'_spec.rb')>=0 call vim_rspec#helpers#notice_msg("Running " . s:SpecFile . "...") - let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin",l:default_cmd) + let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin", l:default_cmd) let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") let l:spec = l:spec_bin . " " . l:spec_opts . " -f h " . l:bufn else @@ -99,6 +96,8 @@ function! s:RunSpecMain(type) let s:spec = l:spec " run the spec command + let l:filter = vim_rspec#helpers#build_filter_command(s:plugin_dir) + let s:cmd = l:spec." | ".l:filter "put the result on a new buffer From 418ae3d0bc65eae2fab7247b6ea3c5a982347e2a Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Sat, 23 Jan 2016 22:27:33 +0200 Subject: [PATCH 09/18] Starting to extracting runners --- plugin/vim-rspec.vim | 15 ++++++--------- plugin/vim_rspec/helpers.vim | 4 ++-- plugin/vim_rspec/runners.vim | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 plugin/vim_rspec/runners.vim diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index e82f410..917f938 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -34,16 +34,13 @@ function! s:RunSpecMain(type) let l:default_cmd = vim_rspec#helpers#find_rspec_executable() " run just the current file - if a:type=="file" - if match(l:bufn,'_spec.rb')>=0 - call vim_rspec#helpers#notice_msg("Running " . s:SpecFile . "...") - let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin", l:default_cmd) - let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") - let l:spec = l:spec_bin . " " . l:spec_opts . " -f h " . l:bufn - else - call vim_rspec#helpers#error_msg("Seems ".l:bufn." is not a *_spec.rb file") + if a:type == "file" + try + let l:spec = vim_rspec#runners#file() + catch /^Seems/ + call vim_rspec#helpers#error_msg(v:exception) return - end + endtry elseif a:type=="line" if match(l:bufn,'_spec.rb')>=0 let l:current_line = line('.') diff --git a/plugin/vim_rspec/helpers.vim b/plugin/vim_rspec/helpers.vim index a1d57a8..30cdd12 100644 --- a/plugin/vim_rspec/helpers.vim +++ b/plugin/vim_rspec/helpers.vim @@ -38,12 +38,12 @@ endfunction function! vim_rspec#helpers#build_filter_command(plugin_dir) let default_filter_cmd = a:plugin_dir . "/vim-rspec.rb" let rb_path = vim_rspec#helpers#fetch_var("RspecRBPath", default_filter_cmd) - return "ruby" . db_path + return "ruby" . rb_path endfunction "====== " Local functions "====== function! s:find_nokogiri() - return system("( gem search -i nokogiri &> /dev/null && echo true )") + return system("gem search -i nokogiri &> /dev/null && echo true") endfunction diff --git a/plugin/vim_rspec/runners.vim b/plugin/vim_rspec/runners.vim new file mode 100644 index 0000000..3a34792 --- /dev/null +++ b/plugin/vim_rspec/runners.vim @@ -0,0 +1,21 @@ +function! vim_rspec#runners#file() + call s:check_is_buffer_spec_file() + call vim_rspec#helpers#notice_msg("Running " . s:buffer_name() . "...") + let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin", vim_rspec#helpers#find_rspec_executable()) + let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") + return l:spec_bin . " " . l:spec_opts . " -f h " . s:buffer_name() +endfunction + +"====== +" Local functions +"====== +function! s:check_is_buffer_spec_file() + let l:bufn = s:buffer_name() + if match(l:bufn,'_spec.rb') <= 0 + throw("Seems ".l:bufn." is not a *_spec.rb file") + endif +endfunction + +function! s:buffer_name() + return expand("%:p") +endfunction From 0ecd476d3e9ca67c316de04bd3bcd34e47788377 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Sat, 23 Jan 2016 22:48:20 +0200 Subject: [PATCH 10/18] Extracted line runner --- plugin/vim-rspec.vim | 19 +++++++------------ plugin/vim_rspec/runners.vim | 21 ++++++++++++++++++--- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index 917f938..2afbf46 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -41,19 +41,14 @@ function! s:RunSpecMain(type) call vim_rspec#helpers#error_msg(v:exception) return endtry - elseif a:type=="line" - if match(l:bufn,'_spec.rb')>=0 - let l:current_line = line('.') - - call vim_rspec#helpers#notice_msg("Running Line " . l:current_line . " on " . s:SpecFile . " ") - let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin",l:default_cmd) - let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") - let l:spec = l:spec_bin . " " . l:spec_opts . " -l " . l:current_line . " -f h " . l:bufn - else - call vim_rspec#helpers#error_msg("Seems ".l:bufn." is not a *_spec.rb file") + elseif a:type == "line" + try + let l:spec = vim_rspec#runners#line() + catch /^Seems/ + call vim_rspec#helpers#error_msg(v:exception) return - end - elseif a:type=="rerun" + endtry + elseif a:type == "rerun" if exists("s:spec") let l:spec = s:spec else diff --git a/plugin/vim_rspec/runners.vim b/plugin/vim_rspec/runners.vim index 3a34792..fb74007 100644 --- a/plugin/vim_rspec/runners.vim +++ b/plugin/vim_rspec/runners.vim @@ -1,9 +1,16 @@ function! vim_rspec#runners#file() call s:check_is_buffer_spec_file() + call vim_rspec#helpers#notice_msg("Running " . s:buffer_name() . "...") - let l:spec_bin = vim_rspec#helpers#fetch_var("RspecBin", vim_rspec#helpers#find_rspec_executable()) - let l:spec_opts = vim_rspec#helpers#fetch_var("RspecOpts", "") - return l:spec_bin . " " . l:spec_opts . " -f h " . s:buffer_name() + return s:fetch_spec_bin() . " " . s:fetch_spec_opts() . " -f h " . s:buffer_name() +endfunction + +function! vim_rspec#runners#line() + call s:check_is_buffer_spec_file() + + let l:current_line = line('.') + call vim_rspec#helpers#notice_msg("Running Line " . l:current_line . " on " . s:SpecFile . " ") + return s:fetch_spec_bin() . " " . s:fetch_spec_opts() . " -l " . l:current_line . " -f h " . s:buffer_name() endfunction "====== @@ -19,3 +26,11 @@ endfunction function! s:buffer_name() return expand("%:p") endfunction + +function! s:fetch_spec_bin() + return vim_rspec#helpers#fetch_var("RspecBin", vim_rspec#helpers#find_rspec_executable()) +endfunction + +function! s:fetch_spec_opts() + return vim_rspec#helpers#fetch_var("RspecOpts", "") +endfunction From 52715138fe0f5d52da959e026fdb6230a76a3fef Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Sat, 23 Jan 2016 22:54:09 +0200 Subject: [PATCH 11/18] Small fixes in runners and win_cmd --- plugin/vim_rspec/runners.vim | 2 +- plugin/vim_rspec/win_cmd.vim | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugin/vim_rspec/runners.vim b/plugin/vim_rspec/runners.vim index fb74007..6e9ce8b 100644 --- a/plugin/vim_rspec/runners.vim +++ b/plugin/vim_rspec/runners.vim @@ -9,7 +9,7 @@ function! vim_rspec#runners#line() call s:check_is_buffer_spec_file() let l:current_line = line('.') - call vim_rspec#helpers#notice_msg("Running Line " . l:current_line . " on " . s:SpecFile . " ") + call vim_rspec#helpers#notice_msg("Running Line " . l:current_line . " on " . s:buffer_name() . " ") return s:fetch_spec_bin() . " " . s:fetch_spec_opts() . " -l " . l:current_line . " -f h " . s:buffer_name() endfunction diff --git a/plugin/vim_rspec/win_cmd.vim b/plugin/vim_rspec/win_cmd.vim index a0761c5..2bc24ef 100644 --- a/plugin/vim_rspec/win_cmd.vim +++ b/plugin/vim_rspec/win_cmd.vim @@ -1,5 +1,5 @@ function! vim_rspec#win_cmd#create_output_win() - let isSplitHorizontal = g:FetchVar("RspecSplitHorizontal", 1) + let isSplitHorizontal = vim_rspec#helpers#fetch_var("RspecSplitHorizontal", 1) let splitDirCommand = isSplitHorizontal == 1 ? 'new' : 'vnew' let splitLocation = "botright " @@ -35,6 +35,11 @@ endfunction "====== " Local functions "====== +function! s:SwitchToWindowByName(buffername) + let l:windowNumber = s:FindWindowByBufferName(a:buffername) + call s:SwitchToWindowNumber(l:windowNumber) +endfunction + function! s:FindWindowByBufferName(buffername) let l:windowNumberToBufnameList = map(range(1, winnr('$')), '[v:val, bufname(winbufnr(v:val))]') let l:arrayIndex = match(l:windowNumberToBufnameList, a:buffername) @@ -46,8 +51,4 @@ function! s:SwitchToWindowNumber(number) exe a:number . "wincmd w" endfunction -function! s:SwitchToWindowByName(buffername) - let l:windowNumber = s:FindWindowByBufferName(a:buffername) - call s:SwitchToWindowNumber(l:windowNumber) -endfunction From f93e875ce130b4378996c688a196c5c5dbdeae1d Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Mon, 25 Jan 2016 12:17:38 +0200 Subject: [PATCH 12/18] Starting to refactoring ruby part Also setted up rspec and start to moving to nokogiri --- .rspec | 1 + Gemfile | 4 + plugin/lib/context_renderer.rb | 1 + plugin/lib/failure_renderer.rb | 3 +- plugin/lib/rspec_test_result.rb | 23 ++ plugin/vim-rspec.rb | 25 +- spec/plugin/lib/rspec_test_result_spec.rb | 14 + spec/spec_helper.rb | 25 ++ spec/support/not_all_passed.html | 395 ++++++++++++++++++++++ 9 files changed, 479 insertions(+), 12 deletions(-) create mode 100644 .rspec create mode 100644 plugin/lib/rspec_test_result.rb create mode 100644 spec/plugin/lib/rspec_test_result_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/not_all_passed.html diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..53607ea --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--colour diff --git a/Gemfile b/Gemfile index f5e3d50..9da1503 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,7 @@ source 'https://rubygems.org' gem 'nokogiri', '1.6.7.2' + +gem 'rspec', '3.4.0' +gem 'rspec-its', '1.2.0' +gem 'pry-nav', '0.2.4' diff --git a/plugin/lib/context_renderer.rb b/plugin/lib/context_renderer.rb index ae9d2db..c29ee4a 100644 --- a/plugin/lib/context_renderer.rb +++ b/plugin/lib/context_renderer.rb @@ -13,6 +13,7 @@ def initialize(context, counts) private def render_context_header + puts "[#{(@context/"dl/dt").inner_html}]" end diff --git a/plugin/lib/failure_renderer.rb b/plugin/lib/failure_renderer.rb index c45a7bd..9d52bd7 100644 --- a/plugin/lib/failure_renderer.rb +++ b/plugin/lib/failure_renderer.rb @@ -1,4 +1,5 @@ -# -*- encoding : utf-8 -*- +require_relative 'string_util' + class FailureRenderer include StringUtil diff --git a/plugin/lib/rspec_test_result.rb b/plugin/lib/rspec_test_result.rb new file mode 100644 index 0000000..bca0683 --- /dev/null +++ b/plugin/lib/rspec_test_result.rb @@ -0,0 +1,23 @@ +require 'nokogiri' + +class RspecTestResult + attr_reader :html, :doc + + def initialize(html) + @html = html + @doc = Nokogiri::HTML(html) + end + + def duration_str + fetch_duration_node + .inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"").gsub(/\"/,'') + end + + private + + def fetch_duration_node + doc.css("script") + .select { |script| script.inner_html =~ /duration/ } + .first + end +end diff --git a/plugin/vim-rspec.rb b/plugin/vim-rspec.rb index d2feff9..150a739 100644 --- a/plugin/vim-rspec.rb +++ b/plugin/vim-rspec.rb @@ -1,20 +1,23 @@ # -*- encoding : utf-8 -*- -require "rubygems" -require "hpricot" +require "nokogiri" require 'cgi' -require "#{File.join(File.dirname(__FILE__), "lib/string_util")}" -require "#{File.join(File.dirname(__FILE__), "lib/failure_renderer")}" -require "#{File.join(File.dirname(__FILE__), "lib/context_renderer")}" +require File.join(File.dirname(__FILE__), "lib/string_util") +require File.join(File.dirname(__FILE__), "lib/failure_renderer") +require File.join(File.dirname(__FILE__), "lib/context_renderer") +require File.join(File.dirname(__FILE__), "lib/rspec_test_result") class RSpecOutputHandler def initialize(doc) - @doc=doc + @doc = doc @counts={ - :passed => 0, - :failed => 0, - :not_implemented => 0 + passed: 0, + failed: 0, + not_implemented: 0 } + end + + def render render_header render_examples end @@ -27,7 +30,7 @@ def render_header script.inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"").gsub(/\"/,'') end # results in ["Finished in 0.00482 seconds", "2 examples, 1 failure"] - failure_success_messages,other_stats = stats.partition {|stat| stat =~ /failure/} + failure_success_messages, other_stats = stats.partition {|stat| stat =~ /failure/} render_red_green_header(failure_success_messages.first) other_stats.each do |stat| puts stat @@ -60,4 +63,4 @@ def render_examples end -renderer = RSpecOutputHandler.new(Hpricot(STDIN.read)) +RSpecOutputHandler.new(Hpricot(STDIN.read)).render diff --git a/spec/plugin/lib/rspec_test_result_spec.rb b/spec/plugin/lib/rspec_test_result_spec.rb new file mode 100644 index 0000000..b313945 --- /dev/null +++ b/spec/plugin/lib/rspec_test_result_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' +require './plugin/lib/rspec_test_result' + +describe RspecTestResult do + subject(:result) { described_class.new(input_html) } + + let(:input_html) { File.read(RspecFileExampleProvider.not_all_passed) } + + describe '#duration_str' do + it 'returns proper duration string' do + expect(result.duration_str).to eq 'Finished in 0.80876 seconds' + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..6bcb1a6 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,25 @@ +$TESTING=true + +# require File.join(File.dirname(__FILE__), '../plugin/vim-rspec.rb') + + +# require 'vim-rspec' +require 'rspec/its' +require 'pry-nav' + +Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f } + +class RspecFileExampleProvider + def self.not_all_passed + File.join File.dirname(__FILE__), 'support/not_all_passed.html' + end +end + +RSpec.configure do |config| + config.mock_with :rspec + + config.filter_run focus: true + config.run_all_when_everything_filtered = true + + config.order = "random" +end diff --git a/spec/support/not_all_passed.html b/spec/support/not_all_passed.html new file mode 100644 index 0000000..49cf413 --- /dev/null +++ b/spec/support/not_all_passed.html @@ -0,0 +1,395 @@ +Run options: include {:focus=>true} + +All examples were filtered out; ignoring {:focus=>true} + + + + RSpec results + + + + + + + + +
+ +
+
+

RSpec Code Examples

+
+ +
+ + + +
+ +
+

 

+

 

+
+
+ + +
+
+
+
EmptyUser
+ +
should respond to #guest?0.00322s
+ + + + +
+ should respond to #forget_me2! + 0.02465s +
+
expected #<EmptyUser:0x007f95646fdaf0 @role="guest", @id=0> to respond to :forget_me2!
+
./spec/app/core/empty_user_spec.rb:18:in `block (2 levels) in <top (required)>'
+
16  end
+17
+18  it { is_expected.to respond_to :forget_me2! }
+19  it { is_expected.to respond_to :force_forget_me! }
+20end
+
+
+ +
should respond to #admin?0.00176s
+ +
should respond to #force_forget_me!0.00126s
+ +
should respond to #superadmin?0.00104s
+ +
should respond to #moderator?0.00098s
+ +
should respond to #member?0.00095s
+
+
+
+
+
when guest user
+
+
+
+
+
member?
+ +
should be falsey0.00112s
+
+
+
+
+
registered?
+ +
should be falsey0.00129s
+
+
+
+
+
guest?
+ +
should be truthy0.00156s
+
+
+
+
+
when registered user
+
+
+
+
+
guest?
+ +
should be falsey0.18902s
+
+
+
+
+
registered?
+ +
should be truthy0.00971s
+
+
+
+
+
member?
+ +
should be truthy0.01008s
+
+
+
+
+
#posted?
+ +
reutnrs false0.00168s
+
+
+
+
+
#new_record?
+
+
+
+
+
new_record?
+ +
should be truthy0.00149s
+
+
+ + +
+
+ + From d1ace61443e793d03f91f592a2daa618d7f1462b Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Mon, 25 Jan 2016 13:08:32 +0200 Subject: [PATCH 13/18] Starting to refactoring output handler --- plugin/lib/rspec_test_result.rb | 30 +++++++++++++++++++--- plugin/vim-rspec.rb | 31 ++++++++++------------- spec/plugin/lib/rspec_test_result_spec.rb | 18 +++++++++++++ 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/plugin/lib/rspec_test_result.rb b/plugin/lib/rspec_test_result.rb index bca0683..b70b8f7 100644 --- a/plugin/lib/rspec_test_result.rb +++ b/plugin/lib/rspec_test_result.rb @@ -9,15 +9,39 @@ def initialize(html) end def duration_str - fetch_duration_node - .inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"").gsub(/\"/,'') + fetch_duration_node.inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"").gsub(/\"/,'') + end + + def examples_count + fetch_counts_str.match(/(\d+) example/)[1].to_i rescue 0 + end + + def failures_count + fetch_counts_str.match(/(\d+) failure/)[1].to_i rescue 0 + end + + def pending_count + fetch_counts_str.match(/(\d+) pending/)[1].to_i rescue 0 end private + def fetch_counts_str + fetch_counts_node + .inner_html.scan(/".*"/).first + end + + def fetch_counts_node + fetch_script_node_with_inner_pattern(/totals/) + end + def fetch_duration_node + fetch_script_node_with_inner_pattern(/duration/) + end + + def fetch_script_node_with_inner_pattern(pattern) doc.css("script") - .select { |script| script.inner_html =~ /duration/ } + .select { |script| script.inner_html =~ pattern } .first end end diff --git a/plugin/vim-rspec.rb b/plugin/vim-rspec.rb index 150a739..828a5f9 100644 --- a/plugin/vim-rspec.rb +++ b/plugin/vim-rspec.rb @@ -7,10 +7,11 @@ require File.join(File.dirname(__FILE__), "lib/rspec_test_result") class RSpecOutputHandler + attr_reader :test_result - def initialize(doc) - @doc = doc - @counts={ + def initialize(test_result) + @test_result = test_result + @counts = { passed: 0, failed: 0, not_implemented: 0 @@ -25,23 +26,15 @@ def render private def render_header - stats = (@doc/"script").select {|script| script.innerHTML =~ /duration|totals/ } - stats.map! do |script| - script.inner_html.scan(/".*"/).first.gsub(/<\/?strong>/,"").gsub(/\"/,'') - end - # results in ["Finished in 0.00482 seconds", "2 examples, 1 failure"] - failure_success_messages, other_stats = stats.partition {|stat| stat =~ /failure/} - render_red_green_header(failure_success_messages.first) - other_stats.each do |stat| - puts stat - end + render_red_green_header + puts test_result.duration_str puts " " end - def render_red_green_header(failure_success_messages) - total_count = failure_success_messages.match(/(\d+) example/)[1].to_i rescue 0 - fail_count = failure_success_messages.match(/(\d+) failure/)[1].to_i rescue 0 - pending_count = failure_success_messages.match(/(\d+) pending/)[1].to_i rescue 0 + def render_red_green_header + total_count = test_result.examples_count + fail_count = test_result.failure_count + pending_count = test_result.pending_count if fail_count > 0 puts "------------------------------" @@ -63,4 +56,6 @@ def render_examples end -RSpecOutputHandler.new(Hpricot(STDIN.read)).render +test_result = RspecTestResult.new(STDIN.read) + +RSpecOutputHandler.new(test_result).render diff --git a/spec/plugin/lib/rspec_test_result_spec.rb b/spec/plugin/lib/rspec_test_result_spec.rb index b313945..e21e9a4 100644 --- a/spec/plugin/lib/rspec_test_result_spec.rb +++ b/spec/plugin/lib/rspec_test_result_spec.rb @@ -11,4 +11,22 @@ expect(result.duration_str).to eq 'Finished in 0.80876 seconds' end end + + describe '#examples_count' do + it 'returns proper overall examples count' do + expect(result.examples_count).to eq 15 + end + end + + describe '#failures_count' do + it 'returns proper failure examples count' do + expect(result.failures_count).to eq 1 + end + end + + describe '#pending_count' do + it 'returns proper pending examples count' do + expect(result.pending_count).to eq 0 + end + end end From 622b36c3d71fa3804a6ae94451f690ab9ec749ae Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Mon, 25 Jan 2016 17:58:21 +0200 Subject: [PATCH 14/18] WIP: ruby part refactoring almost completed --- plugin/lib/context_renderer.rb | 34 ------------- plugin/lib/failure_renderer.rb | 8 +-- plugin/lib/rspec_context_renderer.rb | 42 +++++++++++++++ plugin/lib/rspec_example_group_result.rb | 26 ++++++++++ plugin/lib/rspec_example_result.rb | 46 +++++++++++++++++ plugin/lib/rspec_test_result.rb | 7 +++ plugin/lib/string_util.rb | 4 ++ plugin/vim-rspec.rb | 6 +-- .../lib/rspec_example_group_result_spec.rb | 25 +++++++++ spec/plugin/lib/rspec_example_result_spec.rb | 51 +++++++++++++++++++ spec/plugin/lib/rspec_test_result_spec.rb | 10 ++++ spec/spec_helper.rb | 12 +++++ spec/support/example_group.html | 34 +++++++++++++ spec/support/failure_example.html | 13 +++++ spec/support/passed_example.html | 1 + 15 files changed, 276 insertions(+), 43 deletions(-) delete mode 100644 plugin/lib/context_renderer.rb create mode 100644 plugin/lib/rspec_context_renderer.rb create mode 100644 plugin/lib/rspec_example_group_result.rb create mode 100644 plugin/lib/rspec_example_result.rb create mode 100644 spec/plugin/lib/rspec_example_group_result_spec.rb create mode 100644 spec/plugin/lib/rspec_example_result_spec.rb create mode 100644 spec/support/example_group.html create mode 100644 spec/support/failure_example.html create mode 100644 spec/support/passed_example.html diff --git a/plugin/lib/context_renderer.rb b/plugin/lib/context_renderer.rb deleted file mode 100644 index c29ee4a..0000000 --- a/plugin/lib/context_renderer.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -*- encoding : utf-8 -*- -class RSpecContextRenderer - # context: an html representation of an rspec context from rspec output - # counts: a hash with :passed, :failed, :not_implemented counters - def initialize(context, counts) - @context=context - @counts=counts - @classes = {"passed"=>"+","failed"=>"-","not_implemented"=>"#"} - render_context_header - render_specs - puts " " - end - - private - def render_context_header - - puts "[#{(@context/"dl/dt").inner_html}]" - end - - def render_specs - (@context/"dd").each do |dd| - render_spec_descriptor(dd) - FailureRenderer.new(dd/"div[@class~='failure']") if dd[:class] =~ /failed/ - end - end - - def render_spec_descriptor(dd) - txt = (dd/"span:first").inner_html - clazz = dd[:class].gsub(/(?:example|spec) /,'') - puts "#{@classes[clazz]} #{txt}" - outcome = clazz.to_sym - @counts[outcome] += 1 - end -end diff --git a/plugin/lib/failure_renderer.rb b/plugin/lib/failure_renderer.rb index 9d52bd7..9dd93bf 100644 --- a/plugin/lib/failure_renderer.rb +++ b/plugin/lib/failure_renderer.rb @@ -12,8 +12,8 @@ def initialize(failure) private - def indent(msg) - " #{msg}" + def failure_message + indent(unescape((@failure/"div[@class~='message']/pre").inner_html.gsub(/\n/,'').gsub(/\s+/,' '))) end def failure_location @@ -22,10 +22,6 @@ def failure_location ) end - def failure_message - indent(unescape((@failure/"div[@class~='message']/pre").inner_html.gsub(/\n/,'').gsub(/\s+/,' '))) - end - def backtrace_details unescape( backtrace_lines.map do |elem| diff --git a/plugin/lib/rspec_context_renderer.rb b/plugin/lib/rspec_context_renderer.rb new file mode 100644 index 0000000..5074799 --- /dev/null +++ b/plugin/lib/rspec_context_renderer.rb @@ -0,0 +1,42 @@ +# +# Renders example group +# +# Parameters: +# example_group - an html representation of an rspec example_group from rspec output +# +class RSpecContextRenderer + attr_reader :example_group + + CLASSES = {"passed"=>"+","failed"=>"-","not_implemented"=>"#"} + + def initialize(example_group) + @example_group = example_group + end + + def render + render_example_group_header + render_specs + puts " " + end + + private + + def render_example_group_header + puts "[#{example_group.header_text}]" + end + + def render_specs + example_group.eaxmples.each do |example| + render_spec_descriptor(example) + end + (example_group/"dd").each do |dd| + FailureRenderer.new(dd/"div[@class~='failure']") if dd[:class] =~ /failed/ + end + end + + def render_spec_descriptor(example) + txt = (dd/"span:first").inner_html + clazz = dd[:class].gsub(/(?:example|spec) /,'') + puts "#{CLASSES[clazz]} #{txt}" + end +end diff --git a/plugin/lib/rspec_example_group_result.rb b/plugin/lib/rspec_example_group_result.rb new file mode 100644 index 0000000..a527585 --- /dev/null +++ b/plugin/lib/rspec_example_group_result.rb @@ -0,0 +1,26 @@ +require 'nokogiri' +require_relative 'rspec_example_result' + +class RspecExampleGroupResult + attr_reader :context + + def initialize(context) + @context = context + end + + def header_text + fetch_header_node.inner_html + end + + def examples + context.css('dd').map do |context| + RspecExampleResult.new(context) + end + end + + private + + def fetch_header_node + context.css('dl dt').first + end +end diff --git a/plugin/lib/rspec_example_result.rb b/plugin/lib/rspec_example_result.rb new file mode 100644 index 0000000..c9ac1ca --- /dev/null +++ b/plugin/lib/rspec_example_result.rb @@ -0,0 +1,46 @@ +require 'nokogiri' +require_relative './string_util.rb' + +class RspecExampleResult + include ::StringUtil + + attr_reader :context + + def initialize(context) + @context = context + end + + def header_text + context.css('span:first').first.inner_html + end + + def html_class + context['class'].gsub(/(?:example|spec) /,'') + end + + def failure_message + prepared_inner_html = context.css('div.message > pre').first.inner_html + .gsub(/\n/,'').gsub(/\s+/,' ') + unescape(prepared_inner_html) + end + + def failure_location + unescape( + context.css('div.backtrace > pre').first.inner_html.split("\n").map do |line| + "#{indent(line.strip)}" + end.join("\n") + ) + end + + def backtrace_lines + context.css('pre.ruby > code').first.inner_html + .scan(/()(\d+)(<\/span>)(.*)/) + .reject { |line| line[3] =~ ignore_line_if_matches } + end + + private + + def ignore_line_if_matches + /install syntax to get syntax highlighting/ + end +end diff --git a/plugin/lib/rspec_test_result.rb b/plugin/lib/rspec_test_result.rb index b70b8f7..5e94772 100644 --- a/plugin/lib/rspec_test_result.rb +++ b/plugin/lib/rspec_test_result.rb @@ -1,4 +1,5 @@ require 'nokogiri' +require_relative 'rspec_example_group_result' class RspecTestResult attr_reader :html, :doc @@ -24,6 +25,12 @@ def pending_count fetch_counts_str.match(/(\d+) pending/)[1].to_i rescue 0 end + def example_groups + doc.css('div.example_group').map do |context| + RspecExampleGroupResult.new(context) + end + end + private def fetch_counts_str diff --git a/plugin/lib/string_util.rb b/plugin/lib/string_util.rb index dc611a5..b762e06 100644 --- a/plugin/lib/string_util.rb +++ b/plugin/lib/string_util.rb @@ -6,4 +6,8 @@ def strip_html_spans(code) def unescape(html) CGI.unescapeHTML(html) end + + def indent(msg) + " #{msg}" + end end diff --git a/plugin/vim-rspec.rb b/plugin/vim-rspec.rb index 828a5f9..388a52d 100644 --- a/plugin/vim-rspec.rb +++ b/plugin/vim-rspec.rb @@ -3,7 +3,7 @@ require 'cgi' require File.join(File.dirname(__FILE__), "lib/string_util") require File.join(File.dirname(__FILE__), "lib/failure_renderer") -require File.join(File.dirname(__FILE__), "lib/context_renderer") +require File.join(File.dirname(__FILE__), "lib/rspec_context_renderer") require File.join(File.dirname(__FILE__), "lib/rspec_test_result") class RSpecOutputHandler @@ -49,8 +49,8 @@ def render_red_green_header end def render_examples - (@doc/"div[@class~='example_group']").each do |context| - RSpecContextRenderer.new(context, @counts) + test_result.example_groups.each do |example_group| + RSpecContextRenderer.new(example_group).render end end diff --git a/spec/plugin/lib/rspec_example_group_result_spec.rb b/spec/plugin/lib/rspec_example_group_result_spec.rb new file mode 100644 index 0000000..a98a553 --- /dev/null +++ b/spec/plugin/lib/rspec_example_group_result_spec.rb @@ -0,0 +1,25 @@ +require 'spec_helper' +require './plugin/lib/rspec_example_group_result' + +describe RspecExampleGroupResult do + subject(:result) { described_class.new(doc) } + + let(:doc) { Nokogiri::HTML(input_html) } + let(:input_html) { File.read(RspecFileExampleProvider.example_group_path) } + + describe '#header_text' do + it 'returns proper string' do + expect(result.header_text).to eq 'EmptyUser' + end + end + + describe '#examples' do + it 'returns proper number of examples' do + expect(result.examples.count).to eq 7 + end + + it 'returns wraps examples' do + expect(result.examples.first).to be_kind_of(RspecExampleResult) + end + end +end diff --git a/spec/plugin/lib/rspec_example_result_spec.rb b/spec/plugin/lib/rspec_example_result_spec.rb new file mode 100644 index 0000000..0a7287f --- /dev/null +++ b/spec/plugin/lib/rspec_example_result_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' +require './plugin/lib/rspec_example_result' + +describe RspecExampleResult do + subject(:result) { described_class.new(doc) } + + let(:doc) { Nokogiri::HTML.fragment(input_html).css('dd').first } + let(:input_html) { File.read(RspecFileExampleProvider.passed_example_path) } + + describe '#header_text' do + it 'returns proper text' do + expect(result.header_text).to eq 'should respond to #member?' + end + end + + context 'when passed example' do + describe '#html_class' do + it 'returns proper value' do + expect(result.html_class).to eq 'passed' + end + end + end + + context 'when failure example' do + let(:input_html) { File.read(RspecFileExampleProvider.failure_example_path) } + + describe '#html_class' do + it 'returns proper value' do + expect(result.html_class).to eq 'failed' + end + end + + describe '#failure_message' do + it 'returns proper value' do + expect(result.failure_message).to eq 'expected # to respond to :forget_me2!' + end + end + + describe '#failure_location' do + it 'returns proper value' do + expect(result.failure_location).to eq " ./spec/app/core/empty_user_spec.rb:18:in `block (2 levels) in '" + end + end + + describe '#backtrace_lines' do + it 'returns proper values' do + expect(result.backtrace_lines).to eq [["", "16", "", " end"], ["", "17", "", ""], ["", "18", "", " it { is_expected.to respond_to :forget_me2! }"], ["", "19", "", " it { is_expected.to respond_to :force_forget_me! }"], ["", "20", "", "end"]] + end + end + end +end diff --git a/spec/plugin/lib/rspec_test_result_spec.rb b/spec/plugin/lib/rspec_test_result_spec.rb index e21e9a4..b963e64 100644 --- a/spec/plugin/lib/rspec_test_result_spec.rb +++ b/spec/plugin/lib/rspec_test_result_spec.rb @@ -29,4 +29,14 @@ expect(result.pending_count).to eq 0 end end + + describe '#example_groups' do + it 'returns proper number of example groups' do + expect(result.example_groups.count).to eq 12 + end + + it 'returns wrapped example groups' do + expect(result.example_groups.first).to be_kind_of(RspecExampleGroupResult) + end + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6bcb1a6..cfdfd70 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,18 @@ class RspecFileExampleProvider def self.not_all_passed File.join File.dirname(__FILE__), 'support/not_all_passed.html' end + + def self.example_group_path + File.join File.dirname(__FILE__), 'support/example_group.html' + end + + def self.passed_example_path + File.join File.dirname(__FILE__), 'support/passed_example.html' + end + + def self.failure_example_path + File.join File.dirname(__FILE__), 'support/failure_example.html' + end end RSpec.configure do |config| diff --git a/spec/support/example_group.html b/spec/support/example_group.html new file mode 100644 index 0000000..cb61246 --- /dev/null +++ b/spec/support/example_group.html @@ -0,0 +1,34 @@ +
+
+
EmptyUser
+ +
should respond to #guest?0.00322s
+ + + + +
+ should respond to #forget_me2! + 0.02465s +
+
expected #<EmptyUser:0x007f95646fdaf0 @role="guest", @id=0> to respond to :forget_me2!
+
./spec/app/core/empty_user_spec.rb:18:in `block (2 levels) in <top (required)>'
+
16  end
+17
+18  it { is_expected.to respond_to :forget_me2! }
+19  it { is_expected.to respond_to :force_forget_me! }
+20end
+
+
+ +
should respond to #admin?0.00176s
+ +
should respond to #force_forget_me!0.00126s
+ +
should respond to #superadmin?0.00104s
+ +
should respond to #moderator?0.00098s
+ +
should respond to #member?0.00095s
+
+
diff --git a/spec/support/failure_example.html b/spec/support/failure_example.html new file mode 100644 index 0000000..4bccf13 --- /dev/null +++ b/spec/support/failure_example.html @@ -0,0 +1,13 @@ +
+should respond to #forget_me2! +0.02465s +
+
expected #<EmptyUser:0x007f95646fdaf0 @role="guest", @id=0> to respond to :forget_me2!
+
./spec/app/core/empty_user_spec.rb:18:in `block (2 levels) in <top (required)>'
+
16  end
+17
+18  it { is_expected.to respond_to :forget_me2! }
+19  it { is_expected.to respond_to :force_forget_me! }
+20end
+
+
diff --git a/spec/support/passed_example.html b/spec/support/passed_example.html new file mode 100644 index 0000000..17bd25c --- /dev/null +++ b/spec/support/passed_example.html @@ -0,0 +1 @@ +
should respond to #member?0.00095s
From ce456e8c1fab5c740835ab14cd23c6e397ead31a Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Mon, 25 Jan 2016 23:13:01 +0200 Subject: [PATCH 15/18] Completed ruby part refactoring :relaxed: --- plugin/lib/failure_renderer.rb | 26 +++++++++----------- plugin/lib/rspec_context_renderer.rb | 11 +++------ plugin/lib/rspec_example_result.rb | 14 +++++++++-- plugin/vim-rspec.rb | 4 +-- spec/plugin/lib/rspec_example_result_spec.rb | 24 ++++++++++++++++-- spec/spec_helper.rb | 4 --- 6 files changed, 51 insertions(+), 32 deletions(-) diff --git a/plugin/lib/failure_renderer.rb b/plugin/lib/failure_renderer.rb index 9dd93bf..40647b0 100644 --- a/plugin/lib/failure_renderer.rb +++ b/plugin/lib/failure_renderer.rb @@ -3,8 +3,13 @@ class FailureRenderer include StringUtil - def initialize(failure) - @failure = failure + attr_reader :example + + def initialize(example) + @example = example + end + + def render puts failure_message puts failure_location puts backtrace_details @@ -13,18 +18,20 @@ def initialize(failure) private def failure_message - indent(unescape((@failure/"div[@class~='message']/pre").inner_html.gsub(/\n/,'').gsub(/\s+/,' '))) + indent(unescape(example.failure_message)) end def failure_location unescape( - (@failure/"div[@class='backtrace']/pre").inner_html.split("\n").map { |line| "#{indent(line.strip)}" }.join("\n") + example.failure_location.split("\n") + .map { |line| "#{indent(line.strip)}" } + .join("\n") ) end def backtrace_details unescape( - backtrace_lines.map do |elem| + example.backtrace_lines.map do |elem| linenum = elem[1] code = elem[3].chomp code = strip_html_spans(code) @@ -32,13 +39,4 @@ def backtrace_details end.join ) end - - def backtrace_lines - (@failure/"pre[@class='ruby']/code").inner_html.scan(/()(\d+)(<\/span>)(.*)/).reject { |line| line[3] =~ ignore_line_if_matches } - end - - def ignore_line_if_matches - /install syntax to get syntax highlighting/ - end - end diff --git a/plugin/lib/rspec_context_renderer.rb b/plugin/lib/rspec_context_renderer.rb index 5074799..235387d 100644 --- a/plugin/lib/rspec_context_renderer.rb +++ b/plugin/lib/rspec_context_renderer.rb @@ -7,7 +7,6 @@ class RSpecContextRenderer attr_reader :example_group - CLASSES = {"passed"=>"+","failed"=>"-","not_implemented"=>"#"} def initialize(example_group) @example_group = example_group @@ -26,17 +25,13 @@ def render_example_group_header end def render_specs - example_group.eaxmples.each do |example| + example_group.examples.each do |example| render_spec_descriptor(example) - end - (example_group/"dd").each do |dd| - FailureRenderer.new(dd/"div[@class~='failure']") if dd[:class] =~ /failed/ + FailureRenderer.new(example).render if example.failure? end end def render_spec_descriptor(example) - txt = (dd/"span:first").inner_html - clazz = dd[:class].gsub(/(?:example|spec) /,'') - puts "#{CLASSES[clazz]} #{txt}" + puts "#{example.status_sign} #{example.header_text}" end end diff --git a/plugin/lib/rspec_example_result.rb b/plugin/lib/rspec_example_result.rb index c9ac1ca..da237ff 100644 --- a/plugin/lib/rspec_example_result.rb +++ b/plugin/lib/rspec_example_result.rb @@ -4,12 +4,18 @@ class RspecExampleResult include ::StringUtil + CLASSES_TO_SIGN_MAPPING = {"passed"=>"+","failed"=>"-","not_implemented"=>"#"} + attr_reader :context def initialize(context) @context = context end + def failure? + context['class'] =~ /failed/ + end + def header_text context.css('span:first').first.inner_html end @@ -19,9 +25,8 @@ def html_class end def failure_message - prepared_inner_html = context.css('div.message > pre').first.inner_html + context.css('div.message > pre').first.inner_html .gsub(/\n/,'').gsub(/\s+/,' ') - unescape(prepared_inner_html) end def failure_location @@ -30,6 +35,7 @@ def failure_location "#{indent(line.strip)}" end.join("\n") ) + context.css('div.backtrace > pre').first.inner_html end def backtrace_lines @@ -38,6 +44,10 @@ def backtrace_lines .reject { |line| line[3] =~ ignore_line_if_matches } end + def status_sign + CLASSES_TO_SIGN_MAPPING[html_class] + end + private def ignore_line_if_matches diff --git a/plugin/vim-rspec.rb b/plugin/vim-rspec.rb index 388a52d..ac9c83f 100644 --- a/plugin/vim-rspec.rb +++ b/plugin/vim-rspec.rb @@ -4,6 +4,8 @@ require File.join(File.dirname(__FILE__), "lib/string_util") require File.join(File.dirname(__FILE__), "lib/failure_renderer") require File.join(File.dirname(__FILE__), "lib/rspec_context_renderer") +require File.join(File.dirname(__FILE__), "lib/rspec_example_result") +require File.join(File.dirname(__FILE__), "lib/rspec_example_group_result") require File.join(File.dirname(__FILE__), "lib/rspec_test_result") class RSpecOutputHandler @@ -45,7 +47,6 @@ def render_red_green_header puts "+ PASS: All #{total_count} Specs Pass!" puts "++++++++++++++++++++++++++++++" end - end def render_examples @@ -53,7 +54,6 @@ def render_examples RSpecContextRenderer.new(example_group).render end end - end test_result = RspecTestResult.new(STDIN.read) diff --git a/spec/plugin/lib/rspec_example_result_spec.rb b/spec/plugin/lib/rspec_example_result_spec.rb index 0a7287f..4b32d4c 100644 --- a/spec/plugin/lib/rspec_example_result_spec.rb +++ b/spec/plugin/lib/rspec_example_result_spec.rb @@ -14,16 +14,30 @@ end context 'when passed example' do + describe '#failure?' do + its(:failure?) { is_expected.to be_falsey } + end + describe '#html_class' do it 'returns proper value' do expect(result.html_class).to eq 'passed' end end + + describe '#status_sign' do + it 'returns proper sign' do + expect(result.status_sign).to eq '+' + end + end end context 'when failure example' do let(:input_html) { File.read(RspecFileExampleProvider.failure_example_path) } + describe '#failure?' do + its(:failure?) { is_expected.to be_truthy } + end + describe '#html_class' do it 'returns proper value' do expect(result.html_class).to eq 'failed' @@ -32,13 +46,13 @@ describe '#failure_message' do it 'returns proper value' do - expect(result.failure_message).to eq 'expected # to respond to :forget_me2!' + expect(result.failure_message).to eq 'expected #<EmptyUser:0x007f95646fdaf0 @role="guest", @id=0> to respond to :forget_me2!' end end describe '#failure_location' do it 'returns proper value' do - expect(result.failure_location).to eq " ./spec/app/core/empty_user_spec.rb:18:in `block (2 levels) in '" + expect(result.failure_location).to eq "./spec/app/core/empty_user_spec.rb:18:in `block (2 levels) in <top (required)>'" end end @@ -47,5 +61,11 @@ expect(result.backtrace_lines).to eq [["", "16", "", " end"], ["", "17", "", ""], ["", "18", "", " it { is_expected.to respond_to :forget_me2! }"], ["", "19", "", " it { is_expected.to respond_to :force_forget_me! }"], ["", "20", "", "end"]] end end + + describe '#status_sign' do + it 'returns proper sign' do + expect(result.status_sign).to eq '-' + end + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cfdfd70..3ef4126 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,5 @@ $TESTING=true -# require File.join(File.dirname(__FILE__), '../plugin/vim-rspec.rb') - - -# require 'vim-rspec' require 'rspec/its' require 'pry-nav' From 56f5a47f0561eb2ec61f3615f8a374fa09f06709 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Mon, 25 Jan 2016 23:28:58 +0200 Subject: [PATCH 16/18] Fixes after real testing --- plugin/vim-rspec.rb | 2 +- plugin/vim-rspec.vim | 6 +++--- plugin/vim_rspec/helpers.vim | 2 +- plugin/vim_rspec/win_cmd.vim | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugin/vim-rspec.rb b/plugin/vim-rspec.rb index ac9c83f..d6d806d 100644 --- a/plugin/vim-rspec.rb +++ b/plugin/vim-rspec.rb @@ -35,7 +35,7 @@ def render_header def render_red_green_header total_count = test_result.examples_count - fail_count = test_result.failure_count + fail_count = test_result.failures_count pending_count = test_result.pending_count if fail_count > 0 diff --git a/plugin/vim-rspec.vim b/plugin/vim-rspec.vim index 2afbf46..73527ad 100644 --- a/plugin/vim-rspec.vim +++ b/plugin/vim-rspec.vim @@ -97,9 +97,9 @@ function! s:RunSpecMain(type) setl buftype=nofile silent exec "r! ".s:cmd setl syntax=vim-rspec - silent exec "nnoremap :call vim_rspec#win_cmd#try_to_open()" - silent exec 'nnoremap n /\/.*spec.*\::call vim_rspec#win_cmd#try_to_open()' - silent exec 'nnoremap N ?/\/.*spec.*\::call vim_rspec#win_cmd#try_to_open()' + silent exec "nnoremap :call vim_rspec#win_cmd#try_to_open('" . s:SpecFile . "')" + silent exec "nnoremap n /\/.*spec.*\::call vim_rspec#win_cmd#try_to_open('" . s:SpecFile . "')" + silent exec "nnoremap N ?/\/.*spec.*\::call vim_rspec#win_cmd#try_to_open('" . s:SpecFile . "')" silent exec "nnoremap q :q:wincmd p" setl nolist setl foldmethod=expr diff --git a/plugin/vim_rspec/helpers.vim b/plugin/vim_rspec/helpers.vim index 30cdd12..aca1b03 100644 --- a/plugin/vim_rspec/helpers.vim +++ b/plugin/vim_rspec/helpers.vim @@ -38,7 +38,7 @@ endfunction function! vim_rspec#helpers#build_filter_command(plugin_dir) let default_filter_cmd = a:plugin_dir . "/vim-rspec.rb" let rb_path = vim_rspec#helpers#fetch_var("RspecRBPath", default_filter_cmd) - return "ruby" . rb_path + return "ruby " . rb_path endfunction "====== diff --git a/plugin/vim_rspec/win_cmd.vim b/plugin/vim_rspec/win_cmd.vim index 2bc24ef..ec47cca 100644 --- a/plugin/vim_rspec/win_cmd.vim +++ b/plugin/vim_rspec/win_cmd.vim @@ -13,18 +13,18 @@ function! vim_rspec#win_cmd#create_output_win() silent! exec "edit RSpecOutput" endfunction -function! vim_rspec#win_cmd#try_to_open() +function! vim_rspec#win_cmd#try_to_open(spec_file) " Search up to find '*_spec.rb' call search("_spec","bcW") let l:line = getline(".") if match(l:line,'^ .*_spec.rb')<0 - call g:ErrorMsg("No spec file found.") + call vim_rspec#helpers#error_msg("No spec file found.") return end let l:tokens = split(l:line,":") " move back to the other window, if available - call s:SwitchToWindowByName(s:SpecFile) + call s:SwitchToWindowByName(a:spec_file) " open the file in question (either in the split) " that was already open, or in the current win From 7cb6e26f15765ffc0cfe6feb7d4508aaf26f1daa Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Mon, 25 Jan 2016 23:35:41 +0200 Subject: [PATCH 17/18] Fix RunSpecLine command for RSpec 3+ --- plugin/vim_rspec/runners.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/vim_rspec/runners.vim b/plugin/vim_rspec/runners.vim index 6e9ce8b..b606339 100644 --- a/plugin/vim_rspec/runners.vim +++ b/plugin/vim_rspec/runners.vim @@ -10,7 +10,7 @@ function! vim_rspec#runners#line() let l:current_line = line('.') call vim_rspec#helpers#notice_msg("Running Line " . l:current_line . " on " . s:buffer_name() . " ") - return s:fetch_spec_bin() . " " . s:fetch_spec_opts() . " -l " . l:current_line . " -f h " . s:buffer_name() + return s:fetch_spec_bin() . " " . s:fetch_spec_opts() . " -f h " . s:buffer_name() . ":" . l:current_line endfunction "====== From bdd658d5c8d854f744f0ceabf491a7eadc9d65a1 Mon Sep 17 00:00:00 2001 From: Sergey Gernyak Date: Wed, 3 Feb 2016 17:50:25 +0200 Subject: [PATCH 18/18] Remove hardcoded path to repo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e5a43a9..c95474d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Added into `~/.vimrc` the following line: ``` call plug#begin('~/.vim/plugged') -Plug 'alterego-labs/vim-rspec' +Plug '' call plug#end() ```