# Passing custom arguments to an rspec script. Is this possible?

**URL:** <https://www.ruby-forum.com/t/passing-custom-arguments-to-an-rspec-script-is-this-possible/166219>\
**Category:** RSpec\
**Created:** [April 22, 2009, 11:11pm UTC](https://www.ruby-forum.com/t/passing-custom-arguments-to-an-rspec-script-is-this-possible/166219 "2009-04-22T23:11:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [April 22, 2009, 11:11pm UTC](https://www.ruby-forum.com/t/passing-custom-arguments-to-an-rspec-script-is-this-possible/166219/1 "2009-04-22T23:11:51Z")

</div>

Hi,

I am writing a rspec script to use with selenium-client. I would like  
to pass the script some custom arguments in the command line to change  
a few test settings in the script. However, rspec gives errors when I  
pass arguments to the script because rspec does not expect them. Is  
there any way I can pass custom arguments to an rspec script?

Thanks,  
Stephanie

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [April 23, 2009, 2:27am UTC](https://www.ruby-forum.com/t/passing-custom-arguments-to-an-rspec-script-is-this-possible/166219/2 "2009-04-23T02:27:19Z")

</div>

On Wed, Apr 22, 2009 at 4:06 PM, stephanie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi,
> 
> I am writing a rspec script to use with selenium-client. I would like  
> to pass the script some custom arguments in the command line to change  
> a few test settings in the script. However, rspec gives errors when I  
> pass arguments to the script because rspec does not expect them. Is  
> there any way I can pass custom arguments to an rspec script?

Arbitrary arguments, no. You can require arbitrary files though:

spec --require path/to/config/file my\_script.rb

In which case you could configure things in different config files.

Would that work for you?

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [April 23, 2009, 2:38am UTC](https://www.ruby-forum.com/t/passing-custom-arguments-to-an-rspec-script-is-this-possible/166219/3 "2009-04-23T02:38:26Z")

</div>

On Wed, Apr 22, 2009 at 6:37 PM, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> spec --require path/to/config/file my\_script.rb
> 
> In which case you could configure things in different config files.
> 
> Would that work for you?

The other alternative would be:

ruby my\_script.rb --custom-arg

To get that to work, the args have to come after my\_script.rb and  
my\_script.rb would need to require ‘spec/autorun’.

---

<div class="post-metadata">

**Author:** ![stephanie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@stephanie](https://www.ruby-forum.com/u/stephanie)\
**Post date:** [April 23, 2009, 2:51am UTC](https://www.ruby-forum.com/t/passing-custom-arguments-to-an-rspec-script-is-this-possible/166219/4 "2009-04-23T02:51:18Z")

</div>

Thanks, I’ll check out both options. -Stephanie
