[rspec-devel] running only a select group of specs
Ben Mabey
ben at benmabey.com
Tue Aug 19 20:38:26 EDT 2008
Hi all,
I've started to use the nullDB adapter quite a bit on one of my rails
app's spec suite. In fact, I have it as my default adapter and only
turn the real DB adapter on when I have a spec that absolutely requires
it. I call these functional specs and I include my Functional module:
share_as :Functional do
before :all do
ActiveRecord::Base.establish_connection(:test)
end
after :all do
ActiveRecord::Base.establish_connection(:adapter => :nulldb)
end
end
With that said, I am now finding myself wanting to run my unit and
functional specs separately at times... So I would like to be able to do:
rake spec # run all
rake spec:unit
rake spec:functional
I know the easy thing would be to just create separate unit and
functional directories.. but that is something that I would like to
avoid. Besides, that is easy and I like pain. :)
So... what would be a good way to accomplish this?
I thought that if I somehow tagged my specs I could run them
conditionally. So I modified my version of rspec so that I can get
access to my example group options.. meaning, I can now say:
describe "some thing", :functional => true do
...
end
And in my spec_helper I have:
config.before(:all) do
if example_group_options[:functional]
ActiveRecord::Base.establish_connection(:test)
end
end
config.after(:all) do
if example_group_options[:functional]
ActiveRecord::Base.establish_connection(:adapter => :nulldb)
end
end
Now that I have essentially tagged my specs, is there an easy way I
could modify the runner to only run certain specs?
Maybe easy isn't a good word... is there a clean way to do this?
Thanks in advance for any input,
Ben
More information about the rspec-devel
mailing list