Thanks Jason for your reply.
Let me explain what I'm trying to do here. In my rspec script I have 5 
examples(i.e. 5 it blocks) under 1 describe block which I need to repeat 
all these 5 examples sequentially 5 lach times to test the stability of my 
device under test. this is my requirement. What is the best possible way to 
do this?

Thanks,
Satya.

On Thursday, 23 February 2017 18:28:26 UTC+5:30, Jason FB wrote:
>
> Rspec is picky about the "describe" and "it" blocks. Those are methods 
> being called, and as such, create your specs in a "pre-run" place in 
> memory. Generally you should avoid any Ruby code outside of an "it" block 
> (of course, except for the provided Rspec hooks— before(:each), 
> before(:all), etc) as this often causes problems.
>
> First of all, you're not even supposed to have 2 specs with identical 
> names (although you could fix that easily by putting the loop variable 'i' 
> inside of your spec name, like "Example it block for #{i} iteration")
>
> Second of all, you're actually telling Rspec to create 50,000 specs. 
> (Since you two example blocks, actually 100,000 specs). Are you insane? 
> There's no way I could possibly get my Mac — which admittedly is no longer 
> top of the line — to run 100,000 specs in memory.
>
> Why would you run the same spec 100,000 times? What you're trying to do 
> does not make any sense.
>
> Now, perhaps you want to loop through some *operation* 50,000 times. In 
> this case, you'd have *1 spec* that would have the for loop *inside* of 
> it, not the "it" inside of the for loop which is your problem.
>
> And the short answer is : Rspec is a testing tool for Ruby code, 
> specifically *domain logic*. As you say, it is not suitable for stress 
> testing or load testing. For load or stress testing, you'll almost 
> certainly want to do this in a Production environment (or a Staging 
> environment, assuming you have Prod-Staging parity) as you'l need to 
> load/stress test against the real architecture you're running on. 
>
> I've never heard of anyone using Rspec for load or stress testing. Your 
> mileage may vary, and perhaps what you're trying to do is use Rspec to hit 
> an external site (like your Production site), which makes slightly more 
> sense. But still, I see no reason why the for loop is outside of the "it" 
> statement. 
>
> Rspec *does not run procedurally* as the code might suggest (and as many, 
> many junior Ruby people get confused by), it creates the specs first by 
> parsing the whole file ("describe" and "it" are actually methods being 
> called to create specs in memory.), then it runs all the specs after having 
> parsed them. The reason you see it crash without running anything is that 
> you've just maxed out your memory before you've even run your very first 
> spec. All it's doing is maxing out while parsing the file and creating the 
> specs (100,000 of them) in memory. 
>
> -Jason
>
>
>
>
> On Feb 23, 2017, at 5:58 AM, Satya Rao <[email protected] <javascript:>> 
> wrote:
>
> Thanks Jon for your quick reply, what I observed with rspec code is, first 
> it tries to loop over 5 lack times and then try to run it blocks, it means 
> the looping is actually happening twice i.e 10 lack times, is that a rspec 
> a limitation. Is there any other solution other than increasing the RAM? 
>
> And then Rspec is not suitable for stress scenarios?
>  
>
> On Thursday, 23 February 2017 16:22:53 UTC+5:30, Jon Rowe wrote:
>>
>> You’re getting that error because you’re running out of memory, the two 
>> code snippets you describe are not identical, the RSpec one creates more 
>> classes and objects under the hood, you should reduce the amount of specs 
>> you are trying to create at once or make more memory available to Ruby.
>>
>> Hope that helps
>>
>> Jon Rowe
>> ---------------------------
>> [email protected]
>> jonrowe.co.uk
>>
>> On Thursday, 23 February 2017 at 21:13, Satya Rao wrote:
>>
>> Hi Everybody,
>>  I'm new to Rspec. I'm getting '[FATAL] failed to allocate memory' when I 
>> loop through some it blocks over 500000 times. And when tried the same with 
>> pure ruby I'm not getting the fatal error and the execution was successful. 
>> Below is my code.
>>
>> Rspec code:
>>
>> fatal_error_check_spec.rb
>> --------------------------------------
>>
>> describe "fatal error check" do
>> for i in 1 .. 500000
>> it "Example it block 1" do
>> puts "My first it"
>> end
>> it "Example it block 2" do
>> puts "My second it"
>> end
>> end 
>> end
>>
>>
>>
>> When running the above rspec code  gives me an above fatal error after ~4 
>> mins without running anything.
>>
>>
>> Pure Ruby code:
>>
>> fatal_error_check.rb
>> -----------------------------
>>
>> for i in 1 .. 500000
>> puts "My first it"
>> puts "My second it"
>> end
>>
>> When running this ruby code, I didn't get any error and printed those two 
>> puts statements 5 lack times successfully.
>>
>>
>> Please help me with solving the above fatal error issue with Rspec. What 
>> should I do to fix this error.
>>
>>
>> My system env is as follows:
>> -----------------------------------------
>> Windows 7 PC qith 8GB RAM
>> Ruby version: 1.9.3
>> rspec (3.5.0)
>>
>>
>> Please help me to fix this issue.
>>
>>
>> Thanks,
>> Satya.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "rspec" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/rspec/c2824e72-abb7-4374-b2a9-7137acad9aea%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/rspec/c2824e72-abb7-4374-b2a9-7137acad9aea%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/rspec/ea6d9921-0bb7-4126-bdca-fcad936c2215%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/rspec/ea6d9921-0bb7-4126-bdca-fcad936c2215%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
> ----
>
> Jason Fleetwood-Boldt
> [email protected] <javascript:>
> http://www.jasonfleetwoodboldt.com/writing
>
> If you'd like to reply by encrypted email you can find my public key on 
> jasonfleetwoodboldt.com (more about setting GPG: https://gpgtools.org)  
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/ddea19df-ce4f-478f-a43f-31dd5ab2e4e2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to