However cool your build radiator is, mine is cooler – it’s powered by a Raspberry Pi
Category Archives: Uncategorized
Better cucumber tag based logic
Previously, I’ve written up something on how to implement logic around cucumber’s tags. Well, here’s an improvement… instead of using a formatter, it turns out that you can get to a scenario’s tags as an array of strings, eg:
["@complete", "@slow"]
The place to do is in the Before or After blocks in your env.rb file, eg:
That’s a fair bit easier than using a formatter!
Tag based logic in Cucumber
Sometimes cucumber’s Before hook just doesn’t cut it. Here’s a nice hack that allows you to perform some logic during execution of cucumber scenarios when a tag is first come across:
It’s a cucumber formatter that detects when a tag is first come across. When a new tag is found, the perform_logic_for method is called, passing the tag to it. Once you’re in the perform_logic_for method, you can do what you like. I’m doing stuff like checking to see if a directory matches the tag name; if I find one, I load the data into an environment (a great example of when the Before tag isn’t enough). You have free reign in here to do what you like with the tag.
To use it, save the file to features/support/tag_logic.rb, add your own tag logic, and then execute it with:
#cucumber -f pretty -f TestManagement::TagLogic -o /dev/null
I hope that helps!
Small print:
Use the Before hook instead of this if you possibly can.
How to get the RSpec test result in the after block
—UPDATE—
The change I asked for made it into rspec so you can now call example.exception out of the box!
—/UPDATE—
RSpec allows you to run a block of code at the end of each test using the after(:each) method. A change is going to be included in a future (hopefully near future!) version of RSpec that allows you to know what exception the test failed with so that you can decide what to do based on the exception. You’ll be able to do that by asking the example for its exception:
I’ve been using a monkeypatch for a little while that allows me to know if a test passed or failed – I’ve wanted to write out a variable on test failure but until now rspec hasn’t exposed the test result. Here’s the patch:
If you place the above code in your project somewhere, you’ll be able to use it as shown in the following example of its use:
When the next version of RSpec exposes the exception that caused the test to fail, this patch will still work, so it’s fairly well future proof…
NetGear NV+ default admin username and password
My new NetGear NV+ has just arrived. It’s great. Apart from the fact that none of the paperwork mentions the username or password you need to log in to the admin console. If you’re looking for the same info, the details you need are:
- Username: admin
- Password: netgear1
Hope that helps!
RQuery: A thin layer of JQuery over watir/selenium
So I went to a presentation today, run by Aidy Lewis and Josh Chisholm about Josh’s new RQuery project; here’s a braindump of what I remember.
RQuery is not supposed to be a competitor to Selenium or Watir but builds on top of it to provide a few things… the ones that interested me were the ability to query for objects by using css selectors, and the fact that it converts ruby into javascript so that very little work is done inside the browser.
The css selector stuff is done by injecting jQuery into the page that’s being tested (if it’s not already there). This is pretty cool because it means you don’t need to worry about browser specific ways to select stuff (useful, since watir and selenium are/are going to be sat on top of webdriver so browser agnosticism is important). It also means that you don’t need to know xpath – cool if you’re a webdev since you don’t want to learn something new, and you probably already know css!
The ruby-to-javascript stuff also looks pretty cool: instead of running loads of ugly javascript in the browser, the ruby code in your test is converted to some simple jQuery and that is what gets executed. Interesting to note that in the demo we saw, the tester (sorry, didn’t catch your name!) mentioned that the only downside to this is when debugging – did the error occur in ruby? In the ruby-javascript translation? In the CSS? In the browser? In the AUT?
Check out the rQuery wiki for how to get started.
Overall, RQuery looks like a cool project. I’ll be following it for sure…
