Skip to content

Commit

Permalink
Backfill test cases depending on current file
Browse files Browse the repository at this point in the history
Add some missing test cases and remove some superfluous ones:

  1. Remove references to last_spec_line
  2. Add a Spec for RunCurrentSpecFile when in a spec file
  3. Spec for RunNearestSpec when in a spec file
  4. Test that RunAllSpecs runs all specs

Detail:

1. Remove references to last_spec_line

The test for RunCurrentSpecFile included references to a variable
'last_spec_line', and two contexts to handle the case where it is set or
not set.

This variable seems to have never been referenced in the code. It looks
like it was introduced in 6a39ba7, but only in the specs. My guess is
that this was used in a previous attempted implementation of that PR
(#79) and committed by
mistake.

2. Add a Spec for RunCurrentSpecFile when in a spec file

Approach: Create a new buffer and name it differently to the last_spec_file

:bdelete! is used in the after block (as opposed to e.g. :close!) so
that the buffer is actually deleted and new buffers can be created with
the same name in other tests.

Note: previously only the fallback case (calling RunCurrentSpecFile when
not currently in a spec file) was covered by specs.

3. Spec for RunNearestSpec when in a spec file

Approach:
- Set up a spec buffer with a different file name to last_spec_file and
  last_spec_file_with_line
- Write some lines into that buffer
- Jump to some point in the middle of that file

4. Test that RunAllSpecs runs all specs

Previously there was no test case for this.

Approach: regardless of anything else which might be set (e.g.
last_spec) this always runs 'spec'

NOTE: we need to explicitly set g:rspec_command when asserting the
resulting command, because by default the command differs depending on
environment - e.g. the default terminal command first calls 'clear' in
the terminal.
  • Loading branch information
dgmstuart authored and Greg Lazarev committed Jan 30, 2017
1 parent 967da7f commit 52a7259
Showing 1 changed file with 89 additions and 19 deletions.
108 changes: 89 additions & 19 deletions t/rspec_test.vim
Expand Up @@ -94,48 +94,100 @@ describe "RunSpecs"
end

describe "RunCurrentSpecFile"
context "when not in a spec file"
before
let g:rspec_command = "!rspec {spec}"
end

after
unlet g:rspec_command
end

context "when in a spec file"
before
let g:rspec_command = "!rspec {spec}"
new
file controller_spec.rb
end

after
unlet g:rspec_command
bdelete!
end

context "when line number is not set"
it "runs the last spec file"
call Set("s:last_spec_file", "model_spec.rb")
it "runs the current spec file"
call Set("s:last_spec_file", "model_spec.rb")

call Call("RunCurrentSpecFile")
call Call("RunCurrentSpecFile")

Expect Ref("s:rspec_command") == "!rspec model_spec.rb"
end
Expect Ref("s:rspec_command") == "!rspec controller_spec.rb"
end

context "when line number is set"
it "runs the last spec file"
call Set("s:last_spec_file", "model_spec.rb")
call Set("s:last_spec_line", 42)
it "sets last_spec_file to the current file"
call Set("s:last_spec_file", "model_spec.rb")

call Call("RunCurrentSpecFile")
call Call("RunCurrentSpecFile")

Expect Ref("s:rspec_command") == "!rspec model_spec.rb"
end
Expect Ref("s:last_spec_file") == "controller_spec.rb"
end
end

context "when not in a spec file"
it "runs the last spec file"
call Set("s:last_spec_file", "model_spec.rb")

call Call("RunCurrentSpecFile")

Expect Ref("s:rspec_command") == "!rspec model_spec.rb"
end
end
end

describe "RunNearestSpec"
context "not in a spec file"
before
let g:rspec_command = "!rspec {spec}"
end

after
unlet g:rspec_command
end

context "when in a spec file"
before
let g:rspec_command = "!rspec {spec}"
new
file controller_spec.rb
put =[
\ 'it \"is tautological\" do',
\ ' expect(true).to eq',
\ 'end',
\ '',
\ 'it \"is optimistic\" do',
\ ' expect(1 + 1).to eq 3',
\ 'end',
\ ]
5 " jump to the start of the second spec
end

after
unlet g:rspec_command
bdelete!
end

it "runs the current spec file at the current line"
call Set("s:last_spec_file_with_line", "model_spec.rb:42")
call Set("s:last_spec_file", "model_spec.rb")

call Call("RunNearestSpec")

Expect Ref("s:rspec_command") == "!rspec controller_spec.rb:5"
end

it "sets last_spec_file to the current file"
call Set("s:last_spec_file", "model_spec.rb")

call Call("RunNearestSpec")

Expect Ref("s:last_spec_file") == "controller_spec.rb"
end
end

context "not in a spec file"
it "runs the last spec file with line"
call Set("s:last_spec_file_with_line", "model_spec.rb:42")

Expand Down Expand Up @@ -167,6 +219,24 @@ describe "RunLastSpec"
end

describe "RunAllSpecs"
before
let g:rspec_command = "!rspec {spec}"
end

after
unlet g:rspec_command
end

it "runs all specs"
call Set("s:last_spec", "model_spec.rb:42")
call Set("s:last_spec_file", "model_spec.rb")
call Set("s:last_spec_file_with_line", "model_spec.rb:42")

call Call("RunAllSpecs")

Expect Ref("s:rspec_command") == "!rspec spec"
end

it "sets s:last_spec to 'spec'"
call Call("RunAllSpecs")

Expand Down

0 comments on commit 52a7259

Please sign in to comment.