Spinach VS Cucumber for Bdd in Rails

cucumber vs spinach in term of speed

This might be a dead question, but the bottleneck for either of these is likely to be the Rails startup time, along with the driver that Capybara uses rather than any underlying differences between the test suites.

https://github.com/jnicklas/capybara#selecting-the-driver

Running spinach tests in parallel

Finally I was able to run spinach in parallel. The thing was that paralell testing works only when spinach features are in a default directory

/features 

regardless of spinach.yml setting.

I had them in

/spinach_features

Unfortunatelly parallel tests take longer than regular tests and the output is displayed without colours so basically there are no benefits of using them (at least in my case).

Rails BDD: Cucumber alternatives

If some important readers of the tests, say clients, want to read the tests and they don't know programming, there is no good alternative of Cucumber to write tests as plain text, as I know.

But Cucumber comes with cost. You need to write plain text and write code to parse it. A programmer can read the tests code directly without plain text as media. If the clients don't need to read tests and but the stories only, Cucumber is not necessary.

So there came the Steak gem, which uses Ruby and Cucumber like syntax to write tests, direct tests, no plain text to parse.

But later, this gem is out of date because Capybara has eaten Steak. Capybara now has same BBD syntax like feature(which equals describe in Rspec), scenario which equals it and so on.

So my conclusion is, if no need to prepare plain text for sombody outside of developers to read, use Capybara, good and simple. Otherwise still use Cucumber.

Good Cucumber examples in the wild?

You can read diaspora's cucumber tests. It's a pretty big project so I think you can learn something from it.

Call one step from within another, Spinach

execute is an internal method that shouldn't be used from a feature. If you want to execute a step from another step you do have to underscore it. Spinach maintainers suggest extracting the logic in "I am a facility's administrator" and "I create a patient" step to another method, and calling this very method from other steps.

step "I create a patient as a facility's administrator" do
log_as_facility_admin
create_patient
end

def log_as_facility_admin
# something
end

def create_patient
# something
end

source: https://github.com/codegram/spinach/issues/132

How to test if an img tag points to an existing image?

The way to check, without having to use Selenium or any other drivers, was to extract the src attribute from the img element (Thanks MrDanA), and check the status code after visiting that URL:

page.should have_css("#profile_search_results .profile img.avatar", :count => some_profiles)
img = page.first(:css, "#profile_search_results .profile img.avatar")
visit img[:src]
page.status_code.should be 200


Related Topics



Leave a reply



Submit