Feedback wanted from guard-rspec & guard-spork users about integration testing and a funky regex to exclude .*integration_spec.rb

50 views
Skip to first unread message

Jean-Michel Garnier

unread,
Nov 6, 2012, 11:07:08 AM11/6/12
to guar...@googlegroups.com
Hi there,

I have adopted Avdi Grimm's naming convention for integration specs (*_integration_spec.rb) from Object on Rails.

I use Spork for specs which load the full rails stack such as controllers, integration models specs, ... For models unit tests and libs, I don't want the overhead of Spork.

The challenge was to come up with a simple regex using "Negative lookbehind assertion" in order to avoid running specs twice each time a file is saved. I found out a bit late that the "ignore" keyword from Guard DSL is global.

I'd like some feedback about that approach. What do you use for this? Is it overkill. I have seen some people using an "unit" folder.

Thanks,

JM

This is how my Guardfile looks:


group
'tests-with-spork' do guard 'rspec', :version => 2, :cli => "--drb", :all_after_pass => false do watch('spec/spec_helper.rb') { "spec" } watch(%r{^spec/controllers/.+_spec\.rb$}) watch(%r{^spec/models/.+integration_spec\.rb$}) watch(%r{^spec/helpers/.+_spec\.rb$}) watch(%r{^spec/routing/.+_spec\.rb$}) watch(%r{^spec/requests/.+_spec\.rb$}) watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_integration_spec.rb" } watch(%r{^app/helpers/(.+)\.rb$}) { |m| "spec/helpers/#{m[1]}_spec.rb" } watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m| [ "spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb" ] end watch(%r{^spec/support/(.+)\.rb$}) { "spec" } watch('config/routes.rb') { "spec/routing" } watch('app/controllers/application_controller.rb') { "spec/controllers" } watch(%r{^spec/lib/.+_integration_spec\.rb$}) end end group 'unit-tests' do guard 'rspec', :version => 2, :all_on_start => false, :all_after_pass => false, :bundler => false do watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } # ?<! Negative lookbehind assertion: ensures that the preceding characters do not match 'integration', # but doesn't include those characters in the matched text watch(%r{^spec/models/.*(?<!integration)_spec\.rb$}) watch(%r{^spec/lib/.*(?<!integration)_spec\.rb$}) end end

Thibaud Guillaume-Gentil

unread,
Nov 11, 2012, 9:05:49 AM11/11/12
to guar...@googlegroups.com
Hi Jean-Michel,

Yeah I think it's overkill, if I understand well your setup you have some spec in /lib that are using Spork & integration specs?

Why not having only unit-test style with /lib files and a specific folder ("spec/integration") for your integrations specs. I'm not sure about the advantage of using _integration_spec.rb...

So it would give something like that:

group 'tests-with-spork' do

  guard 'rspec', :version => 2, :cli => "--drb", :all_after_pass => false do
    watch('spec/spec_helper.rb') { "spec" }

    watch(%r{^spec/controllers/.+_spec\.rb$}
)
    watch(%r{^spec/models/.+_spec\.rb$})
    watch(%r{^spec/helpers/.+_spec\.rb$})
    watch(%r{^spec/routing/.+_spec\.rb$})
    watch(%r{^spec/requests/.+_spec\.rb$})
    watch(%r{^spec/integration/.+_spec\.rb$})

    watch(%r{^app/models/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
    watch(%r{^app/helpers/(.+)\.rb$}) { |m| "spec/helpers/#{m[1]}_spec.rb" }
    watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
      [
              "spec/routing/#{m[1]}_routing_spec.rb",
              "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb"
      ]
    end

    watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
    watch('config/routes.rb') { "spec/routing" }
    watch('app/controllers/application_controller.rb') { "spec/controllers"
 }
  
end
end

group 'unit-tests' do
  guard 'rspec', :version => 2, :all_on_start => false, :all_after_pass => false, :bundler => false do
    watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb"
 }
    watch(%r{^spec/lib/.+_spec\.rb$})
  end
end

Jean-Michel Garnier

unread,
Nov 12, 2012, 6:42:31 AM11/12/12
to guar...@googlegroups.com
On Sun, Nov 11, 2012 at 3:05 PM, Thibaud Guillaume-Gentil <guillau...@gmail.com> wrote:
Hi Jean-Michel,

Yeah I think it's overkill, if I understand well your setup you have some spec in /lib that are using Spork & integration specs?

yes:)
 

Why not having only unit-test style with /lib files and a specific folder ("spec/integration") for your integrations specs. I'm not sure about the advantage of using _integration_spec.rb...

I agree it's overkill & I'll try to simplify with a spec/lib/integration. It was fun to dig regex though

Thx for the feedback & awesome podcast by the way:)

Thibaud Guillaume-Gentil

unread,
Nov 12, 2012, 7:46:06 AM11/12/12
to guar...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages