Skip to content

Commit

Permalink
Merge pull request #13 from lmarburger/guard-cucumber
Browse files Browse the repository at this point in the history
---

Read and save failed features if `#run_all` fails. Heres the workflow Im going for:

1. Save Feature1
2. Feature1 -> fail
3. Save a file somewhere in the codebase
4. Feature1 -> pass
5. All features -> Feature2 fail
6. Save a file somewhere in the codebase
7. Feature2 -> pass
8. All features -> pass

From what I can tell, theres no way to tell guard-cucumber to rerun the saved failed features without calling `#run_on_change`. Heres my Guardfile:

```ruby
guard cucumber, :cli => --no-profile --drb --color --strict --format progress --format rerun --out rerun.txt,
                  :all_on_start => false do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$}) { features }
  watch(%r{^app/assets/.+$})       { features }

  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
    Dir[File.join("**/#{m[1]}.feature")][0] || features
  end

  # Rerun failed features
  watch(config/routes.rb)
  watch(%r{^app/(.*)\.rb})
end
```

Its cheating, but Im passing non-feature filenames to guard-cucumber which its smart enough to ignore. The end result is when an app file is saved, the failed features are rerun.

Ive only started using guard yesterday so please let me know if Im missing something obvious. I wouldnt be surprised. In the mean time, Im going to give this patch a try today and see how it feels.
  • Loading branch information
netzpirat committed Jul 4, 2011
2 parents c5a7b5d + caf67be commit 9ab08a4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/guard/cucumber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def start
def run_all
passed = Runner.run(['features'], options.merge({ :message => 'Running all features' }))

@failed_paths = [] if passed
if passed
@failed_paths = []
else
@failed_paths = read_failed_features if @options[:keep_failed]
end

@last_failed = !passed

passed
Expand Down
25 changes: 25 additions & 0 deletions spec/guard/cucumber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,31 @@
Guard::Cucumber::Runner.should_receive(:run).with(['features/bar'], default_options).and_return(true)
subject.run_on_change(['features/bar'])
end

it 'should save failed features' do
Guard::Cucumber::Runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(false)
File.should_receive(:exist?).with('rerun.txt').and_return true
File.stub_chain(:open, :read).and_return 'features/foo'
File.should_receive(:delete).with('rerun.txt')
subject.run_all

Guard::Cucumber::Runner.should_receive(:run).with(['features/bar', 'features/foo'], default_options).and_return(true)
Guard::Cucumber::Runner.should_receive(:run).with(['features'], default_options.merge(:message => 'Running all features')).and_return(true)
subject.run_on_change(['features/bar'])
end

it 'should not save failed features if keep_failed is disabled' do
run_options = default_options.merge :keep_failed => false
subject = Guard::Cucumber.new([], :keep_failed => false)

Guard::Cucumber::Runner.should_receive(:run).with(['features'], run_options.merge(:message => 'Running all features')).and_return(false)
File.should_not_receive(:exist?).with('rerun.txt').and_return true
subject.run_all

Guard::Cucumber::Runner.should_receive(:run).with(['features/bar'], run_options).and_return(true)
Guard::Cucumber::Runner.should_receive(:run).with(['features'], run_options.merge(:message => 'Running all features')).and_return(true)
subject.run_on_change(['features/bar'])
end
end

describe '#reload' do
Expand Down

0 comments on commit 9ab08a4

Please sign in to comment.