When you do `3.times` in an existing spec you’re using an already setup `ExampleGroup` instance which links into the reporter.
With your code you create an isolated example group and use that to create your examples meaning they have no link to the current setup or reporter. My code restores that link by using the existing example group as a generator. Jon Rowe --------------------------- [email protected] jonrowe.co.uk On Friday, 12 December 2014 at 01:49, siva wrote: > > > Hi Jon Rowe > > # spec/requests/sample_spec.rb > > 3.times do > example "expected 1 + 1 should eq to 2" do > expect(1+1).to eq(2) > end > end > > When I ran above code it generated 3 test cases. How this is different from > above code? Could please explain? > > On Thursday, 14 August 2014 17:07:45 UTC+5:30, Jon Rowe wrote: > > This doesn’t work because you’re not registering the example groups you’re > > creating with, a simpler way to do this would be: > > > > # spec/support/generate_test_cases.rb > > > > module RSpec > > module GenerateTestCases > > > > def generate_test_cases > > TestGenerator.new(self).generate_test_cases > > end > > > > class TestGenerator < Struct.new(:rspec) > > def generate_test_cases > > 3.times do > > rspec.describe "Test Cases" do > > example do > > expect(1+1).to eq(2) > > end > > end > > end > > end > > end > > end > > end > > > > > > > > Jon Rowe > > --------------------------- > > [email protected] (javascript:) > > jonrowe.co.uk (http://jonrowe.co.uk) > > > > > > On Thursday, 14 August 2014 at 19:28, siva wrote: > > > > > > > > Hi > > > > > > # spec/support/generate_test_cases.rb > > > > > > module RSpec > > > module GenerateTestCases > > > > > > def generate_test_cases > > > TestGenerator.new.generate_test_cases > > > end > > > > > > class TestGenerator < RSpec::Core::ExampleGroup > > > def generate_test_cases > > > 3.times do > > > TestGenerator.describe "Test Cases" do > > > example do > > > expect(1+1).to eq(2) > > > end > > > end > > > end > > > end > > > end > > > end > > > end > > > > > > RSpec.configure do |rspec| > > > rspec.extend RSpec::GenerateTestCases > > > end > > > > > > RSpec::SharedContext.send(:include, RSpec::GenerateTestCases) > > > > > > # spec/models/user_spec.rb > > > > > > RSpec.describe "User" do > > > generate_test_cases > > > end > > > > > > > > > When I run above test cases it shows 0 examples to run. What I am doing > > > wrong? How can I generate multiple test cases? Could help me? > > > > > > Thanks in advance. > > > ~ > > > -- > > > 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/cb8b6886-7f33-4dab-870d-73495262c792%40googlegroups.com > > > > > > (https://groups.google.com/d/msgid/rspec/cb8b6886-7f33-4dab-870d-73495262c792%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] > (mailto:[email protected]). > To post to this group, send email to [email protected] > (mailto:[email protected]). > To view this discussion on the web visit > https://groups.google.com/d/msgid/rspec/c98d3969-981d-4f00-8088-5f639a96f2c1%40googlegroups.com > > (https://groups.google.com/d/msgid/rspec/c98d3969-981d-4f00-8088-5f639a96f2c1%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]. 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/994ACB31E8014C188436B79D306EBE4F%40jonrowe.co.uk. For more options, visit https://groups.google.com/d/optout.
