Pergunta

I have been using the watirspec-master files as examples to write my own RSpec tests. I recently encountered a situation in which I need to test for an exception thrown by a click or set event. I wrote the following test based on code in the checkbox_spec.rb file. I just changed the original from the lambda syntax to expect syntax.

el4 = browser.checkbox(:id, "category_8")
expect { el4.set }.to raise_error(ObjectDisabledException)

When executed, this code complains about an uninitialized constant ObjectDisabledException. The lambda syntax produces the same error. The full error response is below.

Failure/Error: lambda { el4.set }.should raise_error(ObjectDisabledException)
NameError:
   uninitialized constant RSpec::Core::ExampleGroup::Nested_1::Nested_2::Nested_2::Nested_1::Nested_1::Nested_1::ObjectDisabledException
Shared Example Group: "SF Categories tab" called from ./cf-manage/spec/_suite_sf_abusive_dev_spec.rb:135
# ./cf-manage/spec/_shared_sf_categories.rb:122:in `block (4 levels) in <top (required)>'

I have looked for some documentation on the raise_error method but came up empty. My first thought was that ObjectDisabledException was the wrong value to use. But that value is used repeatedly in the watirspec-master files. Any ideas what is wrong?

Foi útil?

Solução

The ObjectDisabledException (and other Watir exceptions) are custom exceptions that are defined in the Watir::Exception module.

To use them in your specs, you need to specify the exceptions full name:

expect { el4.set }.to raise_error(Watir::Exception::ObjectDisabledException)

Alternatively, if you are doing a lot of exception testing, you should include the Watir::Exception module by adding (some point after requiring watir):

include Watir::Exception

You can see this in the watir-classic gem's implementation.rb and watir-webdriver's spec_helper.rb.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top