test using message and ethanol value with a lot of cases

6 views
Skip to first unread message

Alexey Zenovich

unread,
Mar 15, 2017, 6:01:55 PM3/15/17
to rspec
Hi all!

I want to test my parse sentence module using a lot of examples. I know that I can create cycle in rspec as 

describe ".test" do
  {"a" => "a", "b" => "b", "c" => "c"}.each do |m, e|
     it "#{m} to be equal #{a}" do
        expect(m).to eq(e)
     end
  end
end

Does exist any method to load test cases ({"a" => "a", "b" => "b", "c" => "c"}) from file or from method? Helper metods are unavailable in describe/context blocks.
I don't want to do it in one `it` block as one test.

Thanks!

Jon Rowe

unread,
Mar 15, 2017, 7:50:15 PM3/15/17
to rs...@googlegroups.com
The inside of describe / context block are the insides of classes so you have to use class level methods / module functions. You could easily write code to load this from a file. e.g.

module Support
  def self.load_sentence_cycle
    JSON.parse File.read(‘spec/support/sentence.json’)
  end
end

RSpec.describe ‘test’ do
  Support.load_sentence_cycle.each do |key, value|
    ...
  end
end

Jon Rowe
---------------------------

--
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 rspec+un...@googlegroups.com.
To post to this group, send email to rs...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rspec/21381216-c419-47b5-8fe9-7cfe6a07ffea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages