How to unload "require" in ruby ​​/ rspec?

We are currently running rspec tests that check the loading of specific libraries / models. In particular, we want to check that when creating the object, we return the correct Watir object: Watir :: Browser for FF and Chrome and Watir :: Safari for Safari.

We have already tried this: Unload the ruby ​​class, but it just removes the constant, which we don’t want.

This is usually not a problem, but due to compatibility issues with safariwatir and watir-webdriver it is not. He is mistaken:

superclass mismatch for class UnknownObjectException 

And to β€œfix” this, we basically have to choose which webdriver to load (from here the original logic that we plan to test)

Is there any way to solve this? Our tests pass, and not just in general. Therefore, we basically should skip the step only to get around the required problem.

+4
source share
3 answers

New Anser: NEWS FLASH webdriver now supports Safari! ditch safariwatir and do it all with webdriver. I just found out about it today at Test Automation Bazaar, so I have few details. I would expect to see some blog posts about this from the Watir community next week or so as soon as people recover from the conference.

UPDATE. Details can now be found on the watir-webdriver blog on how to do work with Safari

+2
source

Classes in Ruby are objects, but the idea of ​​classes as "one on one execution / object space" exists only because objects of the Ruby class are assigned as constants.

Since your classes are named using the theater module, you can dynamically check the type of object. If this is not enough, you can duck type. Since you mentioned compatibility issues, there are methods that exist for those that are not for the other (for which you can test), or there are methods that return different values ​​for each of them (which you can test for.)

0
source

I handled something similar to this using conditional logic when I need the watir stone, so only one version is needed, based on setting up the environment. I can provide more detailed information later, perhaps after the bazaar automation test has finished, and I have some time to think and dig up some code samples for you.

0
source

Source: https://habr.com/ru/post/1402999/


All Articles