I'm using the latest rspec-rails 1.2.2 with rails 2.3.2, and I'm
trying to get it to work with spec_server. This is on Mac/Leopard,
with the stock ruby, all gems installed in /Library/Ruby/. I have
configured:
# config/environments/test.rb
config.cache_classes = false
# spec/spec.opts
--drb
The tests run nice and fast, so I know they're running against the
spec_server, but when I make a change to my model which should toggle
the result of a test, it doesn't change until I restart the
spec:server. I have tried running it with combinations of:
rake spec:server:start
script/spec_server
script/autospec
autospec
The specs run, but no reloading makes it useless. Any ideas?
Thanks,
Andrew Vit
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
Are you explicitly using require anywhere?
Scott
$ rake RAILS_ENV=development spec:server:start
$ RAILS_ENV=development script/autospec
And it looks the same. (If I change the model file, the tests re-run
but it obviously doesn't get reloaded: even if I add a syntax error,
it still runs.)
Not sure where you mean about the explicit require. All my specs files
have require spec_helper at the top, which is how they come out of the
box...
Thanks for your help,
Andrew
> >http://rubyforge.org/mailman/listinfo/rspec-users
>
> _______________________________________________
> rspec-users mailing list
> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Actually I meant poking around your app with a browser in dev mode ;)
I'm pretty sure that rails will still try to run the test environment,
even with RAILS_ENV set to a different value, anyway.
> And it looks the same. (If I change the model file, the tests re-run
> but it obviously doesn't get reloaded: even if I add a syntax error,
> it still runs.)
>
> Not sure where you mean about the explicit require. All my specs files
> have require spec_helper at the top, which is how they come out of the
> box...
>
I was thinking of any explicit requires which may occur in app/ and lib/.
AFAIK, this is more of a rails loading issue than an rspec one.
Scott
Ok, I get it, I wasn't sure what you were driving at! ;-) Yes,
everything is reloading fine in the browser under development.
> I'm pretty sure that rails will still try to run the test environment,
> even with RAILS_ENV set to a different value, anyway.
The RAILS_ENV is being set conditionally in my script files, except
script/autospec where it isn't defined.
ENV["RAILS_ENV"] ||= 'test'
> I was thinking of any explicit requires which may occur in app/ and lib/.
Nothing out of the ordinary...
> AFAIK, this is more of a rails loading issue than an rspec one.
I just tried this on a clean new rails app, and the reloading still
doesn't work when running spec_server and autospec with --drb. It
works fine when I'm not using spec_server, but then it reloads all of
rails each time. Works fine, except when using spec_server.
The rspec site says:
[http://rspec.info/rails/runners.html]
> Note that there are some classes and modules that, by default, won’t get reloaded
> by Rails, which means they won’t be reloaded by spec_server. There are a number
> of strategies available for coercing Rails to reload files every time in a given
> environment. See the Rails documentation for more information.
Does that include my app/models? I wouldn't have thought so... Another
post on this mailing list seemed to suggest those don't need manual
reloading and "just work".
$ gem list rails
rails (2.3.2)
$ gem list rspec
rspec (1.2.2)
rspec-rails (1.2.2)
$ rails test_spec_server && cd test_spec_server
$ script/plugin install git://github.com/dchelimsky/rspec-rails.git
$ script/generate rspec
$ script/generate rspec_model car name:string
# edit config/environments/test.rb => config.cache_classes = false
# edit spec/spec.opts => --drb
$ rake spec:server:start
$ script/autospec
# 1 example, 0 failures
# edit app/models/car.rb => add invalid syntax!
# 1 example, 0 failures
Can anyone confirm/reproduce? (Or else tell me what I'm doing wrong?)
Thanks,
Andrew Vit
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
https://rspec.lighthouseapp.com/projects/5645/tickets/759
However, now that it's reloading my app, it's not reloading the setup
from my fixture/factory gems and throwing up a bunch of errors on re-
run. (I've tried it with both factory_girl and machinist now.) These
are required in my spec_helper.rb:
config.gem 'notahat-machinist', :lib => 'machinist', :source =>
'http://gems.github.com'
require File.dirname(__FILE__) + '/blueprints'
or:
config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source
=> 'http://gems.github.com'
# automatically loaded from spec/factories/*.rb
Not sure where to look for a solution.
> rspec-us...@rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
Same problem for me with factory_girl and rspec_rails 1.2.6, work fine
the first time but get a bunch of errors the second.
Any solution? Thanks
In spec_helper?
> On Sun, Mar 29, 2009 at 6:14 PM, Andrew Vit <and...@avit.ca> wrote:
>> It appears this is a bug, with an apparently simple fix in
>> spec_server.rb (rails 2.3 compatibility):
>>
>> https://rspec.lighthouseapp.com/projects/5645/tickets/759
>>
>> However, now that it's reloading my app, it's not reloading the setup
>> from my fixture/factory gems and throwing up a bunch of errors on re-
>> run. (I've tried it with both factory_girl and machinist now.) These
>> are required in my spec_helper.rb:
>>
>> config.gem 'notahat-machinist', :lib => 'machinist', :source =>
>> 'http://gems.github.com'
>> require File.dirname(__FILE__) + '/blueprints'
>>
>> or:
>>
>> config.gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source
>> => 'http://gems.github.com'
>> # automatically loaded from spec/factories/*.rb
>
> In spec_helper?
Hi David,
Sorry, that wasn't clear the way I wrote it. The config.gem directive
was actually in the rails/environments/test.rb file. Then I required
the blueprints.rb file in spec_helper (or in factory_girl's case it
automatically loads the factory files from spec/factories). These
steps showed that rails model reloading wasn't working in 1.2.2 with
rails 2.3.2:
>>> $ gem list rails
>>> rails (2.3.2)
>>> $ gem list rspec
>>> rspec (1.2.2)
>>> rspec-rails (1.2.2)
>>> $ rails test_spec_server && cd test_spec_server
>>> $ script/plugin install git://github.com/dchelimsky/rspec-rails.git
>>> $ script/generate rspec
>>> $ script/generate rspec_model car name:string
>>> # edit config/environments/test.rb => config.cache_classes = false
>>> # edit spec/spec.opts => --drb
>>> $ rake spec:server:start
>>> $ script/autospec
>>> # 1 example, 0 failures
>>> # edit app/models/car.rb => add invalid syntax!
>>> # 1 example, 0 failures
I had given up on spec_server for the time being. The ticket is
resolved now, and I just gave these steps another try with a new app
using updated versions. Reloading the app classes for each run works
fine out of the box now: I can get it to return a success or failure
when I change the model on the fly.
However, the problem comes when adding Factory Girl:
# config/environments/test.rb
# add:
config.gem "thoughtbot-factory_girl", :lib => 'factory_girl'
# spec/factories/car.rb
Factory.define :car do |f|
f.name "Jetta"
end
# spec/models/car_spec.rb
it "should create a new instance given valid attributes" do
car = Factory :car
car.name.should == 'Jetta'
end
It runs fine the first time against drb, but on all subsequent runs I
get the following error until I restart spec_server. None of the lines
in the stacktrace say "rspec" but I was also getting the same error
with Machinist too, so it's not unique to Factory Girl, and I'm
guessing something to do with the reloading.
TypeError in 'Car should create a new instance given valid attributes'
can't dup NilClass
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/
base.rb:2189:in `dup'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/
base.rb:2189:in `scoped_methods'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/
base.rb:2193:in `current_scoped_methods'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/
base.rb:2176:in `scoped?'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/
base.rb:2440:in `send'
/Library/Ruby/Gems/1.8/gems/activerecord-2.3.2/lib/active_record/
base.rb:2440:in `initialize'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/proxy/build.rb:5:in `new'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/proxy/build.rb:5:in `initialize'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/factory.rb:284:in `new'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/factory.rb:284:in `run'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/factory.rb:237:in `create'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/factory.rb:268:in `send'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl/factory.rb:268:in `default_strategy'
/Library/Ruby/Gems/1.8/gems/thoughtbot-factory_girl-1.2.1/lib/
factory_girl.rb:20:in `Factory'
./spec/models/car_spec.rb:11:
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in
`gem_original_require'
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/
dependencies.rb:156:in `require'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/
dependencies.rb:521:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.3.2/lib/active_support/
dependencies.rb:156:in `require'
Andrew Vit
_______________________________________________
rspec-users mailing list
rspec...@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users
No blueprint for class Venue
Any ideas? Thanks!
--
Posted via http://www.ruby-forum.com/.
Actually, I decided to make a tiny release. See this commit:
http://github.com/smtlaissezfaire/fixturereplacement/commit/6aba70c51f0701820b46dc687e965b43e21eca41
Scott
If those libraries use require instead of load, you are screwed. Same
goes for autoload'ing.
If those libraries internally use load, or load_dependency, and you have
cache_classes = false in your dev env, you could try manually reloading
it.
Here's FixtureReplacement in script/console (@ version 2.1) after
reload! is called:
1. http://github.com/timcharper/spork/tree/master
-Ben
That's absolutely awesome.
Have there been any attempts to generalize this, so that mongrel will
fork on each request (a la shotgun)? (I'm still stuck on rails 2.0.2,
so a non-rack based reloading scheme would be great).
Scott
Well, so Spork was really created with testing in mind. It is more
general purpose than spec_server though. You can use it with any Ruby
project, not just Rails. You can also potentially use it with any other
testing framework that adds support for it (I've been meaning to do this
for Cucumber). I know that Tim's original work with Kernel.fork was
actually dealing with Mongrel but I'm not sure what the exact details of
it are. I'll try to find out for you though.
-Ben
Well, so Spork was really created with testing in mind. It is more general purpose than spec_server though. You can use it with any Ruby project, not just Rails. You can also potentially use it with any other testing framework that adds support for it (I've been meaning to do this for Cucumber). I know that Tim's original work with Kernel.fork was actually dealing with Mongrel but I'm not sure what the exact details of it are. I'll try to find out for you though.
I have the same problem. I like spork, but I had to restart the spork
server anytime I made a change to a model file. The only way I know how
to avoid this is to not proload the rails env, which kind of defeats the
purpose.
--
Posted via http://www.ruby-forum.com/.
What does your spec_helper look like?
It should be something like:
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) +
"/../config/environment")
# Load other stuff that only needs to be setup once and never reloaded
(i.e. rspec and configuring it)
end
Spork.each_run do
ActiveRecord::Base.establish_connection # make sure that the db
connection is ready.
require File.expand_path(RAILS_ROOT + "/spec/fixjour_builders.rb") #
You could use FixtureReplacement, FactorGirl, etc...
Spec::Runner.configure do |config|
config.include Fixjour
include SharedSpecHelpers
include DatabaseHelpers
include AuthenticatedTestHelper
end
end
Keep in mind that the code in Spork.prefork must not require any of your
models inadvertently. If your environment file does this or a plugin
does then your models will not be reloaded. Look over your spec_helper
file and try to see who is requiring your models initially. We have
really only tested this on is our apps where Tim and I work... So, there
could very well be bugs we need to iron out.
Sweet! Seems to be working great now.
Looks like the README has changed over the weekend - previously, I had
been starting the spec server with script/spec_server. Running spork
directly seems to work just fine.
Thanks a TON!
Scott
Ok cool. Seems like the bug may of been poor documentation... please
send a pull request if you think it can be improved. :)
-Ben
I found that using
load File.expand_path(File.dirname(__FILE__) + "/blueprints.rb")
in the spec_helper.rb
did the trick.
spork -d > spork.log
More details can be found here:
http://upstream-berlin.com/2009/07/27/kickstart-rspec-with-spork
Hope it helps someone! It took me an hour to solve this :)