[rspec-users] Problems when programmatically defining examples

David Chelimsky dchelimsky at gmail.com
Sat Oct 18 12:50:35 EDT 2008


On Sat, Oct 18, 2008 at 2:13 PM, Jake Benilov <benilov at gmail.com> wrote:
> Hi,
>
> I am trying to code an application that is based on Rspec; I am
> programmatically building examples, and launching the runner with a custom
> formatter. Here are the code snippets from my app:
>
> Launching the runner:
>
>                 example_groups =
> test_expectation.example_groups_for(system_state)
>
>                 @output = StringIO.new
>                 options = Spec::Runner::OptionParser.parse(["--format",
> "RAutotest::Runner::Formatter"], @output, @output)
>                 example_groups.each {|example_group|
> options.add_example_group(example_group) }
>
>                 Spec::Runner::CommandLine.run(options)
>
> Building the example groups:
>
>                     examples =
> Class.new(Spec::Example::ExampleGroup).describe("Statistics")
>                     @expectations.map do |expectation|
>                         examples.it examples.description do
>                             actual_stats_counters.should expectation
>                         end
>                     end
>                     examples
>
> This is working fine, except for one problem. When I am writing examples for
> my app (also using rspec), the examples that are generated within my
> application (the inner examples, so to say) are being added to the
> application's examples (the outer examples).
> This means that if inner expected failures are causing my outer examples to
> fail.
>
> How is it possible for me to verify expected failures without causing my
> examples to fail?

If I understand your question correctly, you can do this:

lambda {
  # stuff that should fail
}.should raise_error(Spec::Expectations::ExpectationNotMetError)

See http://rspec.rubyforge.org/rspec/1.1.8/classes/Spec/Matchers.html#M000434
for more info.

Cheers,
David

>
> Thanks in advance,
> Jake
>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list