spork starting output:
spork # =>
Using RSpec, Rails
-- Starting to fill pool...
Wait until at least one slave is provided before running tests...
** CTRL+BREAK to stop Spork and kill all ruby slave processes **
Spork is ready and listening on 8989!
Preloading Rails environment
Preloading Rails environment
Loading Spork.prefork block...
Loading Spork.prefork block...
# ... some app output info...
Seems like running and it is (i can reach it via browser, there's some response) but every time i try to run specs:
rspec --drb -c ./spec/path/to_file # =>
No DRb server is running. Running in local process instead ...
Why ?
Thank in advance.
environment:
ubuntu 12.10
jruby-1.6.8 # ruby-1.9.2;
rspec 2.13;
spec_helper.rb:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails' #an alternative to webrat
Dir[Rails.root.join("spec/helpers/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.use_transactional_fixtures = true
end
end
Spork.each_run do
FactoryGirl.reload
end
Related
guys.
Rails 3.2.12
I have a sample test spec/models/user_spec.rb
require 'spec_helper'
describe User do
pending "add some examples to (or delete) #{__FILE__}"
end
spec/spec_helper.rb
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.order = "random"
config.color_enabled = true
config.tty = true
config.formatter = :documentation # :progress, :html, :textmate
end
end
Spork.each_run do
end
When I run the test without Spork I get:
$ rspec
c:/ruby/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.2.12/lib/active_support
/dependencies.rb:251:in `block in require': iconv will be deprecated in the futu
re, use String#encode instead.
User
add some examples to (or delete) d:/sites/efiling/spec/models/user_spec.rb (PE
NDING: No reason given)
Pending:
User add some examples to (or delete) d:/sites/efiling/spec/models/user_spec.r
b
# No reason given
# ./spec/models/user_spec.rb:4
Finished in 0.31249 seconds
1 example, 0 failures, 1 pending
Randomized with seed 10437
When I run the test with Spork I get:
$ rspec . --drb
<-- Slave(1) run done!
In Spork window:
Loading Spork.prefork block...
--> DRb magazine_slave_service: 1 provided...
Running tests with args ["--color", "."]...
<-- take tuple(1); slave.run...
-- (1);run done
Done.
-- build slave 1...
Preloading Rails environment
Why does Rspec give no info about pending, failed etc tests when I use it with Spork?
I found an answer to your question: How can I configure rspec to show output with spork?
For your convenience, the way posted to circumvent this error is to add this to the Spork.each_run block:
if Spork.using_spork?
RSpec.configure do |config|
config.reset
config.output_stream = $stdout
end
end
I had the same problems as you, and once I added this in, I was getting normal output again.
I'm new to ROR and wondering if Simplecov provides tests coverage for both TestUnit and RSpec tests in the same project?
I am in the process of migrating some tests we wrote in RSpec from a standalone webapp to an existing webapp that currently uses TestUnit.
I know that both RSpec and TestUnit can live in the same project, but I haven't been able to see how Simplecov will generate coverage for both test frameworks.
When I run on the command line bundle exec rake spec I get:
Coverage report generated for RSpec to /.../coverage. 0 / 0 LOC (0.0%) covered.
when I run bundle exec rake test I get test coverage generated.
The plan is to migrate everything from TestUnit to rspec but with 400+ tests we want to have both TestUnit and RSpec tests covered by Simplecov whilst we migrate to TestUnit.
I'm sure there must be something incorrect in my configuration
Any help would be much appreciated!
I have the following set up:
--- Rakefile ---
require File.expand_path('../config/application', __FILE__)
require 'rake'
require 'simplecov'
if Rails.env == 'test' || Rails.env == 'development'
require 'ci/reporter/rake/test_unit'
require 'ci/reporter/rake/rspec'
end
SimpleCov.start 'rails' do
add_filter "/test/"
add_filter "/spec/"
end
-- spec/spec_helper.rb --
ENV["RAILS_ENV"] ||= 'test'
require 'simplecov'
SimpleCov.start 'rails'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
-- test/test_helper.rb --
require 'simplecov'
SimpleCov.start 'rails' do
add_filter "/vendor/"
end
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
This doesn't answer your question directly, but if it helps, I have a bash script that does a lot of the work for you for porting from TestUnit to RSpec. It's at https://github.com/Noreaster76/porter. You could use it to convert your TestUnit files, and after cleaning up the results a bit, you wouldn't have the issue of having to run both RSpec and TestUnit.
I'm using RSpec for my Rails 3 tests and trying to use Spork.
I followed several tutorials and Spork seems to be running with no errors, but my tests still take the same amount of time to run (43 seconds) with Spork on and off.
How can I figure out what's going on?
Gemfile
gem 'spork', '>=0.9.0.rc9'
spec_helper.rb
require 'rubygems'
require 'spork'
require 'factory_girl'
require 'cover_me'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# 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'
# Force find of factory girl definitions. Tests started failing without this, and the factories could not be found
Factory.find_definitions
# 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|
# == Mock Framework
#
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
#
# config.mock_with :mocha
# config.mock_with :flexmock
# config.mock_with :rr
config.mock_with :rspec
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_path = "#{::Rails.root}/spec/fixtures"
# If you're not using ActiveRecord, or you'd prefer not to run each of your
# examples within a transaction, remove the following line or assign false
# instead of true.
config.use_transactional_fixtures = true
# Needed for Spork
ActiveSupport::Dependencies.clear
end
end
Spork.each_run do
# This code will be run each time you run your specs.
end
When I run →spork to start the server everything looks fine:
→ spork
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
I also have --drb in the .rspec file
It depends on how you measure execution time. If you are including the time it takes to spin up rails that should be faster, but actual test run time wont change.
Spork caches the rails environment which speeds up spin up time but it doesn't speed up actual execution time.
I'm using Ruby 1.9.2, Rails 3.1, Rspec, Postgres and Spork, but I can't get them to play nicely together.
Running the specs for the first time (with Spork running in the background) works fine. However, when I run the specs a second time, it fails with:
Failure/Error: Unable to find matching line from backtrace
PGError:
no connection to the server
# /Users/tom/.rvm/gems/ruby-1.9.2-p180#grapi/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:272:in `exec'
etc....
Any tips appreciated!
You probably also have Devise enabled.
Your problem is described here: https://github.com/sporkrb/spork/wiki/Spork.trap_method-Jujutsu
And more specifically for rails 3.1 here: https://gist.github.com/1054078
The beginning of your prefork block in spec_helper.rb and env.rb should looks like:
Spork.prefork do
Spork.trap_method(Rails::Application, :reload_routes!)
Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
...
Good luck!
If you're using Factory Girl, don't use the 'factory_girl_rails' gem, just use 'factory_girl'.
Spork.each_run do
FactoryGirl.definition_file_paths = [
File.join(Rails.root, 'spec', 'factories')
]
FactoryGirl.find_definitions
end
For anyone using Factory Girl, Machinist, or Shoulda Matchers, make sure you read about Spork's trap_method at: https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu
It solved my problems with Spork and the dropped PostgreSQL connections while testing.
you have to run spork --bootstrap
and after insert some configuration to your spec_helper.rb file, so spork knows about your rails configuration.
As you use RSpec, you can try adding the following code to your spec_helper file:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
# Needed for Spork
ActiveSupport::Dependencies.clear
end
end
Spork.each_run do
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
end
Could you try adding this to Spork.each_run callback and check if it solves the problem?
ActiveRecord::Base.connection_pool.verify_active_connections!
I read the instructions on https://github.com/timcharper/spork/wiki/Spork.trap_method-Jujutsu and found the following.
In my case the solution was to change how machinist blueprints was loaded. My prefork block had this line:
Spork.prefork do
...
require Rails.root.join 'spec/support/blueprints'
...
I removed that from the prefork block and instead added this line to each_run:
Spork.each_run do
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
...
The two lines basically does the same thing, so the main thing seams to be not to load the blueprints in the prefork, but rather in each_run.
Hope it helps!
Given I am a dumb programmer
and I am using rspec
and I am using spork
and I want to debug ...mmm...let's saaay, a spec for Phone.
Then, where should I put the "require 'ruby-debug'" line in order to halt processing at a particular point in the phone_spec.rb? (All I'm asking for is a big fat arrow that even a challenged programmer could see :-3 )
I've tried many locations, and unless I didn't test them correctly, there's something weird going on:
In spec_helper.rb at the following locations:
require 'rubygems'
require 'spork'
<= TRIED IT HERE
ENV["RAILS_ENV"] ||= 'test'
Spork.prefork do
require File.dirname(__FILE__) + "/../config/environment" #unless defined?(RAILS_ROOT)
require 'spec/autorun'
require 'spec/rails'
require 'machinist/active_record'
require 'faker'
require 'sham'
<= TRIED IT HERE
end
Spork.each_run do
require File.expand_path(File.dirname(__FILE__) + "/blueprints")
<= TRIED IT HERE
end
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
Spec::Runner.configure do |config|
config.use_transactional_fixtures = true
config.use_instantiated_fixtures = false
config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
config.before(:all) { Sham.reset(:before_all) }
config.before(:each) { Sham.reset(:before_each) }
<= TRIED IT HERE
end
I'm running Spork and Autospec with ruby-debug. Later versions of Spork have an external ruby-debug library you can require, it's experimental so use at your own risk. In my prefork block I just have :
require 'spork/ext/ruby-debug'
It'll break out to a debug session in the terminal you have Spork running. There are methods etc to initiate remote connection setup and so on, and recent commits have had updates and fixes applied to their debugging functionality so it's under active development. Hopefully it'll be core and tested soon ...
I've always put it in config/environments/test.rb and the put the debugger at the breakpoint in my app code (as opposed to the spec).