# Can Rspec take in a variable from the Command Line and use that variable in all tests?

**URL:** <https://www.ruby-forum.com/t/can-rspec-take-in-a-variable-from-the-command-line-and-use-that-variable-in-all-tests/252887>\
**Category:** RSpec\
**Created:** [August 17, 2019, 2:56pm UTC](https://www.ruby-forum.com/t/can-rspec-take-in-a-variable-from-the-command-line-and-use-that-variable-in-all-tests/252887 "2019-08-17T14:56:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![GeorgeTWalters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5a626/32.png) [@GeorgeTWalters](https://www.ruby-forum.com/u/GeorgeTWalters)\
**Post date:** [August 17, 2019, 2:56pm UTC](https://www.ruby-forum.com/t/can-rspec-take-in-a-variable-from-the-command-line-and-use-that-variable-in-all-tests/252887/1 "2019-08-17T14:56:03Z")

</div>

I have a variable that comes in from the command line. . .  
rspec spec spec/boxing/kata/boxing\_kata\_spec.rb \<spec/fixtures/family\_preferences.csv

The variable. . . family\_file = $stdin. . .can be seen by the first test that uses it, but not by the second test. . .

it “load data” do  
family\_file = $stdin  
csv\_file = Boxing::Kata::LoadFamily.new  
highest\_err\_level, family\_data = csv\_file.load\_validate\_family\_preferences(family\_file)  
expect(family\_data.length).to be \> 0  
end

it “member validation” do  
family\_file = $stdin  
csv\_file = Boxing::Kata::LoadFamily.new  
highest\_err\_level, family\_data = csv\_file.load\_validate\_family\_preferences(family\_file)  
expect(highest\_err\_level).to eql “None”  
end

How can I code this so all tests have access to this variable?

Thanks,  
George

---

<div class="post-metadata">

**Author:** ![GeorgeTWalters](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5a626/32.png) [@GeorgeTWalters](https://www.ruby-forum.com/u/GeorgeTWalters)\
**Post date:** [August 17, 2019, 9:42pm UTC](https://www.ruby-forum.com/t/can-rspec-take-in-a-variable-from-the-command-line-and-use-that-variable-in-all-tests/252887/2 "2019-08-17T21:42:03Z")

</div>

I found that this is not an appropriate way to test with RSpec. No replies necessary.

Thanks,  
George

---

<div class="post-metadata">

**Author:** ![SouravGoswami](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/souravgoswami/32/2543_2.png) [@SouravGoswami](https://www.ruby-forum.com/u/SouravGoswami)\
**Post date:** [August 18, 2019, 5:44am UTC](https://www.ruby-forum.com/t/can-rspec-take-in-a-variable-from-the-command-line-and-use-that-variable-in-all-tests/252887/3 "2019-08-18T05:44:32Z")

</div>

That’s cool. But you can use ARGV and eval all the arguments.  
I don’t know if this can help:

```auto
__b__ , i = binding, 0
ARGV.filter { |x| x[/^[$@]?[a-zA-Z]+=.+$/] }.each(& __b__.method(:eval))
__b__.eval(%q(print("local_variables\t\t#{local_variables.reverse[3..-1]}\n")))

begin
	loop do
		printf "Evaluate %03d> ", i += 1
		STDIN.gets.to_s.strip.tap { |x| puts "#{x}\n# => #{ __b__.eval(x).inspect}" }
	end
rescue Interrupt, SignalException, SystemExit
	puts
	exit! 0
rescue Exception => e
	puts e
	retry
end

```

It should work like this:

 ![image](https://www.ruby-forum.com/uploads/default/original/2X/7/7987bb83ad4459ba5af8de06b9df7e189377326a.jpeg)

Remember you are running a shell in the command line, you have to quote (), “”, ‘’ etc.
