guard / guard-spork

Guard::Spork automatically manage Spork DRb servers
https://rubygems.org/gems/guard-spork
MIT License
296 stars 58 forks source link

Rspec, Capybara, Cucumber, Guard & Spork... loads environment twice, runs features twice? #29

Closed bsodmike closed 12 years ago

bsodmike commented 12 years ago

Added Cucumber and ran spork cucumber --bootstrap to ensure it bootstrapped env.rb, features are now running twice. In fact, launching guard loads the rails environment twice as well?

Starting Spork for RSpec & Cucumber 
Spork server for RSpec & Cucumber successfully started
Guard::RSpec is running, with RSpec 2!
Running all features
Using RSpec
Using Cucumber
Preloading Rails environment
Preloading Rails environment
Disabling profiles...
Loading Spork.prefork block...
Loading Spork.prefork block...

I've already got a bootstrapped spec_helper with rspec and guard-rspec installed. Interestingly, specs are only run once. It's only the features that get run twice...

Ideas?

rymai commented 12 years ago

Could you please provide us your Gemfile, Guardfile and spec_helper.rb? Thanks!

bsodmike commented 12 years ago

Gemfile

source 'http://rubygems.org'

gem 'rails', '3.1.0'

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails', "  ~> 3.1.0"
  gem 'coffee-rails', "~> 3.1.0"
  gem 'uglifier'
end

gem 'jquery-rails'
gem 'cancan'
gem 'devise'
gem 'vidibus-routing_error'
gem 'kaminari'
gem 'rspec-rails', :group => [:development, :test]
gem 'pry', :group => [:development, :test]

group :production do
  gem 'mysql2', '< 0.3'
end

group :development do
  # do bundle install --without production
  gem 'delorean'
  gem 'thin'
  gem 'sqlite3'
  gem 'hirb-unicode'
  gem 'ruby-debug', :platform => :ruby_18
  gem 'ruby-debug19', :platform => :ruby_19
  gem 'rails-erd'
  gem 'yard'
end

group :test do
  gem 'factory_girl_rails'
  gem 'capybara'
  gem 'cucumber-rails'
  gem 'guard-rspec'
  gem 'guard-cucumber'
  gem 'database_cleaner'
  gem 'rb-fsevent'
  gem "spork", "> 0.9.0.rc"
  gem "guard-spork"
end

Guardfile

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('spec/spec_helper.rb')
  watch(%r{^spec/support/.+\.rb$})
end

guard 'rspec', :version => 2, :cli => "-f d --drb", :all_on_start => false, :all_after_pass => false do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$})                           { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('spec/spec_helper.rb')                        { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }
  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }
end

guard 'cucumber', :cli => '--no-profile --color --format pretty --strict' do
  watch(%r{^features/.+\.feature$})
  watch(%r{^features/support/.+$})          { 'features' }
  watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
end

spec_helper.rb

require 'rubygems'
require 'spork'

Spork.prefork do
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require "capybara/rspec"
  require "pry"

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    config.mock_with :rspec
    config.use_transactional_fixtures = true
    # as per http://railscasts.com/episodes/285-spork
    config.treat_symbols_as_metadata_keys_with_true_values = true
    config.filter_run :focus => true
    config.run_all_when_everything_filtered = true    
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.
  FactoryGirl.reload
end

Right now env.rb is back to the way it was before bootstrapping to prevent this whole loading twice issue.

rymai commented 12 years ago

Sorry I'm not familiar with Cucumber, maybe @netzpirat will be of better help...

bsodmike commented 12 years ago

No problem - thanks =)

thibaudgg commented 12 years ago

I think you have missed the :cli => '--drb' option in guard-cucumber :)

bsodmike commented 12 years ago

That was causing spork to crash so I restarted my mbp and re-bootstrapped env.rb and it's working fine now =)


Guard is now watching at '/Users/michaeldesilva/projects/course_mgmt'
Starting Spork for RSpec & Cucumber 
Using RSpec
Using Cucumber
Preloading Rails environment
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Spork is ready and listening on 8990!
Spork server for RSpec & Cucumber successfully started
Guard::RSpec is running, with RSpec 2!
Running all features
Disabling profiles...
Running tests with args ["--no-profile", "--color", "--format", "pretty", "--strict", "--require", "/Users/michaeldesilva/.rvm/gems/ruby-1.9.2-p290@rails31/gems/guard-cucumber-0.6.3/lib/guard/cucumber/notification_formatter.rb", "--format", "Guard::Cucumber::NotificationFormatter", "--out", "/dev/null", "--require", "features", "features"]...
Disabling profiles...
Feature: Schduling Courses As Admin
  In order access the admin dashboard
  As an administrator 
  I need to be able to login

  Scenario: Access Admin Path        # features/admin_access.feature:6
    Given I am on the homepage       # features/step_definitions/web_steps.rb:44
    When I go to the admin root path # features/step_definitions/web_steps.rb:48
    Then I should see "Sign in"      # features/step_definitions/web_steps.rb:105

  Scenario: Signing in via a form               # features/admin_access.feature:11
    Given there are the following admins:       # features/step_definitions/user_steps.rb:1
      | email          | password |
      | admin@cuke.com | password |
    When I go to the admin root path            # features/step_definitions/web_steps.rb:48
    And I fill in "Email" with "admin@cuke.com" # features/step_definitions/web_steps.rb:60
    And I fill in "Password" with "password"    # features/step_definitions/web_steps.rb:60
    And I press "Sign in"                       # features/step_definitions/web_steps.rb:52
    Then I should see "Signed in successfully." # features/step_definitions/web_steps.rb:105
    And I should see "Dashboard"                # features/step_definitions/web_steps.rb:105

2 scenarios (2 passed)
10 steps (10 passed)
0m3.694s
Done.

Thanks!

rymai commented 12 years ago

Ah, sorry I didn't see it! :P Glad all is working fine now!

bsodmike commented 12 years ago

No worries - thanks remy =)