Executing multiple rspec scripts

I’m new to RSpec. I’ve just installed the gem and begun experimenting
with
developing several scripts. From what I’ve seen thus far, it looks like
it
will aid our QA team in testing many web applications. Is there a way
to
execute multiple rspec test scripts from one central file?

On Jul 10, 2008, at 7:19 PM, Robert Stagner wrote:

I’m new to RSpec. I’ve just installed the gem and begun
experimenting with developing several scripts. From what I’ve seen
thus far, it looks like it will aid our QA team in testing many web
applications. Is there a way to execute multiple rspec test scripts
from one central file?

I assume you’re using Rails, from there you can see what RSpec tasks
are available via “rake -T spec”

Matt D., M.S.
Rails | PHP | Linux | MySQL | IT

Email: [email protected]
Skype: matt-darby
Web: http://blog.matt-darby.com

Robert Stagner wrote:

I’m new to RSpec. I’ve just installed the gem and begun experimenting
with developing several scripts. From what I’ve seen thus far, it
looks like it will aid our QA team in testing many web applications.
Is there a way to execute multiple rspec test scripts from one central
file?


Regards,
Robert

Robert,
Welcome to rspec! There are a number of ways you can do this. You can
do it with the command line:
spec spec/*_spec.rb

The way it is generally done is by using a rake task however…
Are you using rails? If so… have you run “./script/generate rspec”?
That will install a spec task for you so you just have to type “rake
spec” to run all of your specs.

If you are in a normal ruby app then you can create your own spec task
by putting this in your Rakefile or tasks dir:

require ‘rubygems’
require ‘spec’
require ‘spec/rake/spectask’

desc “Run the specs under spec/models”
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList[‘spec/*_spec.rb’]
end

If you provide more information on what your setup is we could help
more.

-Ben
http://benmabey.com

Actually, I’m a member of the QA team (limited development experience).
So,
we are attempting to use RSpec without rails. What is Rake? Near the
end
of your response, you list a way of running multiple spec files by
creating
a spec task. Since, I’m not a developer, could you please provide me
with a
clear example on how to do this? Or, if there is an alternative method
on
doing this, please let me know. Thanks again.

My current setup is:

1 spec file that relies on accessing a module of classes to perform
Watir
web app testing. I’ve included a sample of the code below

describe LoginWelcomeScreen do
describe “using IE Explorer” do
before(:each) do
@login = LoginWelcomeScreen.new(IEWebBrowser.instance)
end

it "should support a username text field" do
  @login.test_username_field.should 

be_an_instance_of(Watir::TextField)
end

it "should support a password text field" do
  @login.test_password_field.should

be_an_instance_of(Watir::TextField)
end
.
.
.
.
end

Wow!! That is also very, very helpful. I was able to get rake to work
as
described in an earlier posting, but not without several hours of
tinkering
and reading the RSpec and Rake documentation. Your solution is
certainly
much more direct. Thanks.

Another way to do it instead of the Rake method is what I do…

I create a suite.rb in the spec folder with this…

suite.rb - run all my tests in this folder and below

if FILE == $0
dir = File.dirname(FILE)
tests= Dir["#{dir}//test_.rb"] # anything named test_.rb
tests.concat Dir["#{dir}/
/*_spec.rb"] # anything named *_spec.rb

add additional tests that don;t follow conventional naming schemes

%w(anotherfile, onemorefile).each do |f|
tests << File.join(dir, f) + “.rb”
end

puts “Testing: #{tests.join(’, ')}”

tests.each do |file|
load file, true
end
end

then you can run all your tests via…

ruby suite.rb

You could also use require instead of load, but I use nasty globals in
my tests and I believe the
load doesn’t carry over globals.

YMMV