Git Product home page Git Product logo

turnip's Introduction

Turnip

Join the chat at https://gitter.im/jnicklas/turnip

Test Code Climate

Turnip is a Gherkin extension for RSpec. It allows you to write tests in Gherkin and run them through your RSpec environment. Basically you can write cucumber features in RSpec.

Installation

Install the gem

gem install turnip

Or add it to your Gemfile and run bundle.

group :test do
  gem "turnip"
end

Now edit the .rspec file in your project directory (create it if doesn't exist), and add the following line:

-r turnip/rspec

Development

  • Source hosted at GitHub.
  • Please direct questions, discussion or problems to the mailing list. Please do not open an issue on GitHub if you have a question.
  • If you found a reproducible bug, open a GitHub Issue to submit a bug report.
  • Please do not contact any of the maintainers directly, unless you have found a security related issue.

Pull requests are very welcome (and even better than bug reports)! Please create a topic branch for every separate change you make.

Compatibility and support policy

1. Ruby

Supports Non-EOL Rubies:

  • Support Ruby 2.7 or higher
  • Does not support Ruby (or does not work) 2.6.X or earlier

2. RSpec

In accordance with the RSpec support policy #158 (comment)

  • Support RSpec 3.x the latest or one version before
  • Does not support two version before the latest or earlier
  • Does not work on RSpec 2 or earlier

Example If the latest version is 3.5.x:

  • Support 3.5.x
  • Support 3.4.x
  • Does not support (or does not work) 3.3.x or earlier

Usage

Add a feature file anywhere in your spec directory:

# spec/acceptance/attack_monster.feature
Feature: Attacking a monster
  Background:
    Given there is a monster

  Scenario: attack the monster
    When I attack it
    Then it should die

Now you can run it just like you would run any other rspec spec:

rspec spec/acceptance/attack_monster.feature

It will automatically be run if you run all your specs with rake spec or rspec spec.

Yes, that's really it.

Defining steps

You can define steps on any module:

module MonsterSteps
  step "there is a monster" do
    @monster = Monster.new
  end
end

You can now include this module in RSpec:

RSpec.configure { |c| c.include MonsterSteps }

Steps are implemented as regular Ruby methods under the hood, so you can use Ruby's normal inheritance chain to mix and match steps.

Before/After Hooks

Since Turnip runs atop RSpec, it can utilize RSpec's built-in before and after hooks. To run a hook for all features, specify a global hook with type set to :feature:

config.before(:type => :feature) do
  do_something
end
config.after(:type => :feature) do
  do_something_else
end

You can also limit this to a tag by specifying the tag in the argument to before or after:

config.before(:some_tag => true) do
  do_something
end

Global steps

Turnip has a special module called Turnip::Steps, which is automatically included in RSpec. If you add steps to this module, they are available in all your features. As a convenience, there is a shortcut to doing this, just call step in the global namespace like this:

step "there is a monster" do
  @monster = Monster.new
end

Placeholders

Note that unlike Cucumber, Turnip does not support regexps in step definitions. You can however use placeholders in your step definitions, like this:

step "there is a monster called :name" do |name|
  @monster = Monster.new(name)
end

You can now put values in this placeholder, either quoted or not:

Given there is a monster called Jonas
And there is a monster called "Jonas Nicklas"

You can also specify alternative words and optional parts of words, like this:

step "there is/are :count monster(s)" do |count|
  @monsters = Array.new(count) { Monster.new }
end

That will match both "there is X monster" or "there are X monsters".

You can also define custom step placeholders. More on that later.

Scoped steps

Since steps are defined on modules, you can pick and choose which of them are available in which feature. This can be extremely useful if you have a large number of steps, and do not want them to potentially conflict.

If you had some scenarios which talk to the database directly, and some which go through a user interface, you could implement it as follows:

module InterfaceSteps
  step "I do it" do
    ...
  end
end

module DatabaseSteps
  step "I do it" do
    ...
  end
end

RSpec.configure do |config|
  config.include InterfaceSteps, :interface => true
  config.include DatabaseSteps, :database => true
end

Turnip turns tags into RSpec metadata, so you can use RSpec's conditional include feature to include these steps only for those scenarios tagged the appropriate way. So even though the step is named the same, you can now use it in your feature files like so:

@interface
Scenario: do it through the interface

@database
Scenario: do it through the database

Be careful though not to tag a feature with both @interface and @database in this example. Since steps use the Ruby inheritance chain, the step which is included last will "win", just like any other Ruby method. This might not be what you expect.

Since this pattern of creating a module and including it for a specific tag is very common, we have created a handy shortcut for it:

steps_for :interface do
  step "I do it" do
    ...
  end
end

Check out features/alignment_steps.rb

for an example.

Where to place steps

Turnip automatically loads your spec_helper file. From there you can place your steps wherever you want, and load them however you like. For example, if you were to put your steps in spec/steps, you could load them like this:

Dir.glob("spec/steps/**/*steps.rb") { |f| load f, true }

Before loading your spec_helper, Turnip also tries to load a file called turnip_helper where you can setup anything specific to your turnip examples. You might find it beneficial to load your steps from this file so that they don't have to be loaded when you run your other tests.

If you use Turnip with rspec-rails, most configuration written to rails_helper.rb but not spec_helper.rb. So you should write to turnip_helper like this:

require 'rails_helper'

Then you can write configuration to rails_helper to load your steps.

Calling steps from other steps

Since steps are Ruby methods you can call them like other Ruby methods. However, since the step description likely contains spaces and other special characters, you will probably have to use send to call the step:

step "the value is :num" do |num|
  @value = num
end

step "the value is twice as much as :num" do |num|
  send "the value is :num", num * 2
end

If you use the second step, it will call into the first step, sending in the doubled value.

Sometimes you will want to call the step just like you would from your feature file, in that case you can use the step method:

step "the value is :num" do |num|
  @value = num
end

step "the value is the magic number" do
  step "the value is 3"
end

Methods as steps

You can mark an existing method as a step. This will make it available in your Turnip features. For example:

module MonsterSteps
  def create_monster(name)
    @monster = Monster.new(:name => name)
  end
  step :create_monster, "there is a monster called :name"
end

Custom step placeholders

Do you want to be more specific in what to match in your step placeholders? Do you find it bothersome to have to constantly cast them to the correct type? Turnip supports custom placeholders to solve both problems, like this:

step "there are :count monsters" do |count|
  count.times { Monster.new(name) }
end

placeholder :count do
  match /\d+/ do |count|
    count.to_i
  end

  match /no/ do
    0
  end
end

You would now be able to use these steps like this:

Given there are 4 monsters
Given there are no monsters

Placeholders can extract matches from the regular expressions as well. For example:

placeholder :monster do
  match /(blue|green|red) (furry|bald) monster/ do |color, hair|
    Monster.new(color, hair)
  end
end

These regular expressions must not use anchors, e.g. ^ or $. They may not contain named capture groups, e.g. (?<color>blue|green).

Note that custom placeholders can capture several words separated by spaces and without surrounding quotes, e.g.:

step 'there is :monster in the loft' do |monster|
  # call 'Given there is green furry monster in the loft',
  # :monster will capture 'green furry moster'
end

E.g. Common should / should not steps:

step 'I :whether_to see :text' do |positive, text|
  expectation = positive ? :to : :not_to
  expect(page.body).send expectation, eq(text)
end

placeholder :whether_to do
  match /should not/ do
    false
  end

  match /should/ do
    true
  end
end

Then, it is possible to call the following steps:

Then I should see 'Danger! Monsters ahead!'
 And I should not see 'Game over!'

You can also define custom placeholder without specific regexp, that matches the same value of the default placeholder like this:

placeholder :monster_name do
  default do |name|
    Monster.find_by!(name: name)
  end
end

Table Steps

Turnip also supports steps that take a table as a parameter similar to Cucumber:

Scenario: This is a feature with a table
  Given there are the following monsters:
    | Name    | Hitpoints |
    | Blaaarg | 23        |
    | Moorg   | 12        |
  Then "Blaaarg" should have 23 hitpoints
  And "Moorg" should have 12 hitpoints

The table is a Turnip::Table object which works in much the same way as Cucumber's Cucumber::Ast::Table objects.

E.g. converting the Turnip::Table to an array of hashes:

step "there are the following monsters:" do |table|
  @monsters = {}
  table.hashes.each do |hash|
    @monsters[hash['Name']] = hash['Hitpoints'].to_i
  end
end

or the equivalent:

step "there are the following monsters:" do |table|
  @monsters = {}
  table.rows.each do |(name, hp)|
    @monsters[name] = hp.to_i
  end
end

Unimplemented steps

Turnip mark a scenario as pending when steps in the scenario is not implemented. If you sets raise_error_for_unimplemented_steps as true, turnip will mark a scenario as fail.

It defaults to false, you can change it by adding following configuration to spec/turnip_helper.rb:

RSpec.configure do |config|
  config.raise_error_for_unimplemented_steps = true
end

Substitution in Scenario Outlines

You would be able to use substitution that can be used to DocString and Table arguments in Scenario Outline like Cucumber:

Scenario Outline: Email confirmation
  Given I have a user account with my name "Jojo Binks"
  When an Admin grants me <Role> rights
  Then I should receive an email with the body:
    """
    Dear Jojo Binks,
    You have been granted <Role> rights.  You are <details>. Please be responsible.
    -The Admins
    """
  Examples:
    |  Role     | details                                         |
    |  Manager  | now able to manage your employee accounts       |
    |  Admin    | able to manage any user account on the system   |

Using with Capybara

Just require turnip/capybara in your spec_helper. You can now use the same tags you'd use in Cucumber to switch between drivers e.g. @javascript or @selenium. Your Turnip features will also be run with the :type => :feature metadata, so that Capybara is included and also any other extensions you might want to add.

RSpec custom formatters

Turnip sends notifications to the RSpec reporter about step progress. You can listen for these by registering your formatter class with the following notifications:

class MyFormatter
  RSpec::Core::Formatters.register self, :step_started, :step_passed, :step_failed, :step_pending
  
  def step_passed(step)
    puts "Starting step: #{step.text}"
  end

  # …
end

License

(The MIT License)

Copyright (c) 2011-2012 Jonas Nicklas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

turnip's People

Contributors

aramvisser avatar bdmac avatar cjse avatar dasch avatar davelyon avatar enkessler avatar gitter-badger avatar gongo avatar hanachin avatar harlow avatar haru01 avatar jnicklas avatar kazucocoa avatar kimihito avatar krororo avatar kvokka avatar leoc avatar leshill avatar lukaso avatar pragtob avatar rea-jonpad avatar ryw avatar shaidullinartur avatar swamp09 avatar tadashi0713 avatar taki avatar timabell avatar tothpeter avatar vividmuimui avatar yarospace avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

turnip's Issues

test output formatting

It's really helpful for me to see the steps of a given scenario on separate lines, as opposed to joined on a '->'. It's also more readable to me when the givens, thens, and whens are not excluded.

If I remember correctly, this is how output used to be displayed.

I'm interested in either submitting a pull request, perhaps with configurable output formatting if there are lots of strong believers in the current formatting, or creating a tiny little helper gem that would probably be used by no one on this planet except myself ;)

Thoughts?

Introduce code climate?

Code Climate turned on free support for open source projects some time ago. It's a tool aiming to analyze code and detect bad code (as in duplicated code or overly complex code). I think it's a great tool to see opportunities for refactorings.

If you want I could add turnip there and then make a pull request adding the link to the README :-)

Cheers!

Gherkin cannot load en file

I'm getting strange error that tells me that there is no lexer found for "en". There is of course support for en.

Error output is following:

...gems/gherkin-2.11.2/lib/gherkin/i18n.rb:108:in rescue in lexer': No lexer was found for en (cannot load such file -- gherkin/lexer/en). Supported languages are listed in gherkin/i18n.json. (Gherkin::I18n::LexerNotFound)`

My feature looks like this:

Feature: sign in user
  Background:
    Given there is a registered user

  Scenario: page after successfull sign in
    When user sign in
    Then user should see page

The crazy branch

Hey peeps, especially @bdmac and @leshill. I've been hacking away at a crazy branch of Turnip, you can find it here: https://github.com/jnicklas/turnip/tree/crazy

Let me explain what it does and why:

If we have a step defined like this:

def step("this is a test")
  "foobar"
end

This will actually define two methods inside a Ruby module, called Turnip::Steps. This is kind of the global step module. The two methods are called match: this is a test and execute: this is a test, surprisingly, yes, those are valid method names. The first one of these checks if the the given string matches the step, the second one executes the step given the arguments.

Under the hood we have two modules: Turnip::Define and Turnip::Execute. Both of these have a method called step, the first one defines step methods, like the ones above, the second one executes a step given a string as it would appear in a feature file.

So what's the point of all this? Effectively it turns Turnip steps into Ruby methods. Which means we can use regular Ruby composition via modules and even inheritance to compose sets of steps. Effectively we can do this:

module One
  extend Turnip::Define

  step "cool" do
  end
end

module Two
  include One
  include Turnip::Execute

  def run_step
    step "cool"
  end
end

It's even possible to call super from steps.

It's ridiculous how much this simplifies the internal implementation inside Turnip. We no longer need any kind of logic to determine which steps are available, instead we let RSpec's conditional requires along with the metadata from the tags decide. I got rid of both "scenario_context" and "scenario_runner" and whole chunks of code everywhere.

I am unsure of how to procede from here. Currently I've tried to keep the API compatible, and everything works as expected. Though I got rid of autotagging. I think I could have implemented it, but I personally don't like it as a feature at all, and I couldn't be bothered.

So the point is this: If we use this branch, what steps_for is meant to do can be easily achieved using just standard modules and RSpec's conditional includes. An example:

# before
steps_for :foo do
  step "foo" do
  end
end

# after
module Foo
  extend Turnip::Define

  step "foo" do
  end
end
RSpec.configure { |c| c.include(Foo, :foo => true) }

The second example is obviously quite a bit more verbose, but maybe that's a price worth paying for being more Ruby-ish. If we could get rid of steps_for, that would cut away another huge chunk of the codebase.

What do you guys think? Is this idea totally mad? Brilliant? Both? Should we keep steps_for?

Adding "quotes" doesn't work for "values with spaces"

step 'I follow ":link" in the email' do |link|
  visit_in_email(link)
end

According to your README, both following examples should work:

I follow Confirm in the email
I follow "Confirm my account" in the email

Sadly, the 2nd one doesn't work:

No such step: 'I follow "Confirm my account" in the email'

I have to add a placeholder like the following to make it actually work:

placeholder :link do
  match /.*/ do |link|
    link
  end
end

Is this the expected behavior?

Thanks for this wonderful alternative to Cucumber! 👍

A Step invoking a non-existant step is marked as not found

If a step A invokes a non-existant step B, turnip indicates that step A cannot be found.

Feature

Feature: Correctly indicate which step cannot be found

  Scenario: Step A invoking non-existant step B indicates that Step A cannot be found
    When step A
    Then Turnip should not claim that step A cannot be found

Steps

step "step A" do
  step "step B"
end

Output

Pending:
  Correctly indicate which step cannot be found Step A invoking non-existant step B indicates that Step A cannot be found step A -> Turnip should not claim that step A cannot be found
    # No such step: 'step A'
    # ./spec/acceptance/non_existant.feature:60

Step namespaces

Would be great to have ability to use step namespaces (something along the lines of https://github.com/codegram/spinach with global and shared as modules steps).

And may be default convention for location of step definition files.
Eg,

  • spec/steps/global.rb
  • spec/steps/shared/name_of_shared_module.rb
  • spec/steps/name_of_feature.rb

Minitest support?

Think this would be fun to use Minitest under the hood instead of RSpec... would this be hard to do?

Failure/Error: Unable to find matching line from backtrace

E:\works\try>rspec spec
F

Failures:

  1. Google s searching search in google
    Failure/Error: Unable to find matching line from backtrace
    Selenium::WebDriver::Error::UnknownError:
    Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIWebNavigation.loadURI]

    C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/response.rb:51:in `assert_ok'

    C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/response.rb:15:in`initialize'

    C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/http/common.rb:59:in `new'

    C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/http/common.rb:59:in`create_re

nse'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/http/default.rb:66:in request' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/http/common.rb:40:incall'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/bridge.rb:634:in raw_execute' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/bridge.rb:612:inexecute'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/remote/bridge.rb:110:in get' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/selenium/webdriver/common/navigation.rb:14:into'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/selenium/driver.rb:102:in reset!' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/session.rb:79:inreset!'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara.rb:255:in block in reset_sessions!' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara.rb:255:ineach'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara.rb:255:in reset_sessions!' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/rspec.rb:20:inblock (2 levels) in <top (required)>'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:471:in instance_eval' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:471:ininstance_eval_with_rescue'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:242:in instance_eval_with_rescue' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:31:inrun'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in block in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:ineach'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:85:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hooks.rb:446:inrun_hook'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:350:in run_after_each_hooks' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:298:inrun_after_each'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:120:in block in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:254:inwith_around_each_hooks'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:111:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:390:inblock in run_examples'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:in map' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:386:inrun_examples'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:371:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:372:inblock in run'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:372:in map' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:372:inrun'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in block (2 levels) in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:inmap'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:28:in block in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/reporter.rb:58:inreport'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:25:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:inrun'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

Finished in 16.56 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/acceptance/google_search.feature:68 # Google s searching search in google

Feature files are not loaded with rake spec

In the README, it's said :

"It will automatically be run if you run all your specs with rake spec or rspec spec."

That's not the case for me, .feature files are not loaded in the suite when I use rake, or rake spec

thanks

Support for table steps

Request for support for table-based steps similar to cucumber's (unless this is already there, in which case, it should be in the readme :) )

e.g.

Given I have the following monsters:
| dragon |
| red dragon |
| bearded developer |

or

Given I have the following monsters with attack values:
| monster | attack| (heading row)
| baby dragon | 5 |
| dragon | 10 |
| red dragon | 20 |
| bearded developer | 100 |

Thanks! :)

Background is not being executed before scenario tagged @javascript

EXAMPLE :---

  Background:
    Given there are following areas
      | area   |
      | US    |
      | India |
      |Sweden |
    And I go to "/areas"

  @javascript
  Scenario: Index Page
    Then I should see India

its results

Failure/Error: Then I click on India
     Capybara::ElementNotFound:
       no link or button 'India' found

in this type of case background steps are not being executed

while,

  Background:
    Given there are following areas
      | area   |
      | US    |
      | India |
      |Sweden |
    And I go to "/areas"

  Scenario: Index Page
    Then I should see India

this pass.

is this a bug or I'm doing something wrong?

Spork integration

Hi,

I'm researching whether to use Turnip in my own projects. I use Spork for continuous testing. I found a Stackoverflow issue saying Turnip doesn't work with Spork. Is this accurate? What would be your rec for integrating the two?

thanks.

Custom functions not supported in steps?

Hi!

I am going to move from cucumber to turnip, but while converting my steps an error occured...

The converted stepfile can be found at https://github.com/NobbZ/webworld/blob/feature/turnip/spec/turnip_steps.rb

When I try to run a feature that requires a login I get the following error:

  1) Users Logging in
     Failure/Error: Turnip::StepDefinition.execute(self, Turnip::StepModule.all_steps_for(*scenario_tags), step)
     undefined method `log_in' for #<RSpec::Core::ExampleGroup::Nested_3::Nested_1:0x00000004240960>
     # spec/turnip_steps.rb:20:in `block in <top (required)>'

Is there a way to use my "log_in" function or do I have to repay myself and write the necessarely commands in every step that should use this function?

uninitialized constant Turnip::Config (NameError)

require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'database_cleaner'
  require 'turnip/capybara'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  #include Sorcery::TestHelpers::Rails

  # Don't preload models or routes. They are reloaded by spork.
  Spork.trap_class_method(Rails::Mongoid, :load_models)
  Spork.trap_method(Rails::Application::RoutesReloader, :reload!)

  Capybara.javascript_driver = :webkit

  RSpec.configure do |config|
    config.treat_symbols_as_metadata_keys_with_true_values = true

    Turnip::Config.step_dirs = 'spec/acceptance/steps'
    Turnip::StepModule.load_steps

    config.mock_with :rspec

    config.before(:suite) do
      DatabaseCleaner.clean_with(:truncation)
    end

    config.before(:each) do
      DatabaseCleaner.start
    end

    config.after(:each) do
      DatabaseCleaner.clean
    end
  end

end

Spork.each_run do
  # This code will be run each time you run your specs.
  $rspec_start_time = Time.now
  Fabrication.clear_definitions
end

It gives me uninitialized constant Turnip::Config (NameError)and also uninitialized constant Turnip::StepModule (NameError)

Reloading Spork for RSpec
Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
uninitialized constant Turnip::Config (NameError)
/Users/Nerian/Projects/shopfrog/respondify/spec/spec_helper.rb:25:in `block (2 levels) in <top (required)>'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@global/gems/rspec-core-2.7.1/lib/rspec/core.rb:71:in `configure'
/Users/Nerian/Projects/shopfrog/respondify/spec/spec_helper.rb:22:in `block in <top (required)>'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork.rb:24:in `prefork'
/Users/Nerian/Projects/shopfrog/respondify/spec/spec_helper.rb:3:in `<top (required)>'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/test_framework.rb:138:in `block (2 levels) in preload'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/app_framework/rails.rb:8:in `preload'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/test_framework.rb:134:in `block in preload'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork.rb:62:in `exec_prefork'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/test_framework.rb:120:in `preload'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:25:in `preload'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/runner.rb:74:in `run'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/lib/spork/runner.rb:10:in `run'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/gems/spork-0.9.0.rc9/bin/spork:10:in `<top (required)>'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/bin/spork:19:in `load'
/Users/Nerian/.rvm/gems/ruby-1.9.3-p0@respondify/bin/spork:19:in `<main>'

RSpec mocks are carried over to Turnip specs

When I run just the acceptance specs, everything goes fine. When I run all my specs (unit and acceptance), things start to break.

Using pry and pry-nav to debug the specs, I found out that stubs and mocks I defined on my unit tests are still being returned on my acceptance specs. So I think the rspec-mocks context isn't being "cleared" between Turnip specs or something like that.

Any pointers?

Add cucumber-esque step aliases?

Should Turnip support cucumber-style step aliases for Given, When, Then, and And to ease transitions? Just added a couple of method aliases to dsl.rb on my fork and it seems to work fine. I can add some tests and get that merged in if it's desirable.

Failure/Error: Unable to find matching line from backtrace

D:\Workplaces\Ruby\test>rspec spec
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on [email protected] installed in app-profile
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed
in app-global
*** LOG addons.xpi: New add-on {BBDA0591-3099-440a-AA10-41764D9DB4DB} installed
in winreg-app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found
*** Blocklist::_loadBlocklistFromFile: blocklist is disabled
F

Failures:

  1. Search Search text on youtube Allows searches for general terms
    Failure/Error: Unable to find matching line from backtrace
    Selenium::WebDriver::Error::UnknownError:
    Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_P
    ATH) [nsIWebNavigation.loadURI]

    C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu

m/webdriver/remote/response.rb:51:in assert_ok' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu m/webdriver/remote/response.rb:15:ininitialize'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu
m/webdriver/remote/http/common.rb:59:in new' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu m/webdriver/remote/http/common.rb:59:increate_response'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu
m/webdriver/remote/http/default.rb:66:in request' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu m/webdriver/remote/http/common.rb:40:incall'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu
m/webdriver/remote/bridge.rb:634:in raw_execute' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu m/webdriver/remote/bridge.rb:612:inexecute'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu
m/webdriver/remote/bridge.rb:110:in get' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.38.0/lib/seleniu m/webdriver/common/navigation.rb:14:into'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/selenium/
driver.rb:102:in reset!' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/session.r b:79:inreset!'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara.rb:255:in
block in reset_sessions!' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara.rb:255:in each'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara.rb:255:in
reset_sessions!' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/capybara-2.2.0/lib/capybara/rspec.rb: 20:inblock (2 levels) in <top (required)>'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple_group.rb:471:in instance_eval' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple_group.rb:471:ininstance_eval_with_rescue'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple.rb:242:in instance_eval_with_rescue' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hook s.rb:31:inrun'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hook
s.rb:85:in block in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hook s.rb:85:ineach'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hook
s.rb:85:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/hook s.rb:446:inrun_hook'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple_group.rb:350:in run_after_each_hooks' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple.rb:298:inrun_after_each'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple.rb:120:in block in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple.rb:254:inwith_around_each_hooks'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple.rb:111:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple_group.rb:390:inblock in run_examples'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple_group.rb:386:in map' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple_group.rb:386:inrun_examples'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple_group.rb:371:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple_group.rb:372:inblock in run'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam
ple_group.rb:372:in map' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/exam ple_group.rb:372:inrun'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/comm
and_line.rb:28:in block (2 levels) in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/comm and_line.rb:28:inmap'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/comm
and_line.rb:28:in block in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/repo rter.rb:58:inreport'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/comm
and_line.rb:25:in run' # C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runn er.rb:80:inrun'
# C:/Ruby200/lib/ruby/gems/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runn
er.rb:17:in `block in autorun'

Finished in 19.38 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/test.feature:68 # Search Search text on youtube Allows searches for
general terms
!!! error running onStopped callback: TypeError: callback is not a function
*** LOG addons.manager: shutdown
*** LOG addons.xpi: shutdown

0.2.1 release?

Just wondering what the plans are as far as timing on a new release.

I've got some changes ready for Fabrication to add Turnip step support there like they currently have for Cucumber but it's pretty reliant on Les' changes at this point.

Support files being counted twice

I store my step definitions in spec/support. I just upgraded to 0.3 from 0.2 (and Rails 3.2). All my features were passing on 0.2. I'm now seeing Ambiguous errors for every step in my suite. Looking into it further shows it's matching the step files twice, once with a full path and once with a relative path:

[#<struct Turnip::StepDefinition::Match step_definition=#<Turnip::StepDefinition:0x007ffb4c528ee8 @expression="I am signed in as a teacher", @block=#<Proc:0x007ffb4c528f10@/Users/joe/Projects/barefoot/impact-everyday-web/spec/support/authentication_steps.rb:29>, @regexp=/^I\ am\ signed\ in\ as\ a\ teacher$/>, params=[], block=#<Proc:0x007ffb4c528f10@/Users/joe/Projects/barefoot/impact-everyday-web/spec/support/authentication_steps.rb:29>>, #<struct Turnip::StepDefinition::Match step_definition=#<Turnip::StepDefinition:0x007ffb4cae9d28 @expression="I am signed in as a teacher", @block=#<Proc:0x007ffb4caeaa98@spec/support/authentication_steps.rb:29>, @regexp=/^I\ am\ signed\ in\ as\ a\ teacher$/>, params=[], block=#<Proc:0x007ffb4caeaa98@spec/support/authentication_steps.rb:29>>]

Any thoughts on this?

rake spec:requests points to `spec/requests` - should it be replaced with spec:acceptance?

I'm having a lot of fun with Turnip since I started using it a few days ago, and I'm trying to configure it correctly for my project. I noticed that listing the rake tasks using rake -T results in the following spec tasks:

    rake spec             # Run all specs in spec directory (excluding plugin specs) / Run RSpec cod...
    rake spec:controllers # Run the code examples in spec/controllers
    rake spec:models      # Run the code examples in spec/models
    rake spec:requests    # Run the code examples in spec/requests
    rake spec:routing     # Run the code examples in spec/routing
    rake stats            # Report code statistics (KLOCs, etc) from the application

As I don't have request specs anymore when using Turnip, I think the spec:requests task should be removed and replaced with a spec:acceptance task. What's the best way to do this? Could this be done within the Turnip gem itself?

How could I tag a scenario so that it doesn't get executed?

How could I tag a scenario so that it doesn't get executed?

Feature: Log in
  Background:
    Given there is a school

  @Some-tag
  Scenario: The admin logs in
    When the user admin logs in
    Then it should see the home page

That scenario should not be executed.

Capybara tests fail on master

After grabbing the latest changes to steps_for Capybara seems to be busted. I am getting:

 Failure/Error: Turnip::StepDefinition.execute(self, Turnip::StepModule.all_steps_for(*feature_tags), step)
 NoMethodError:
   undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1:0x007ffc0ce5cfa8>

This only seems to be an issue when using "-r turnip/capybara" via .rspec file. If I add the require directly to spec_helper I do not get this error.

rspec does not automatically run my features

I have some features tests under spec/acceptance, but they are not found when I run rspec:

josh@macbuech:~/Documents/Work/Sientia/tests/transition (features/devise *)$ rspec
  1) DashboardsController GET 'show' returns http success
     Failure/Error: response.should be_success
       expected success? to return true, got false
     # ./spec/controllers/dashboards_controller_spec.rb:8:in `block (3 levels) in <top (required)>'

 6/6 |===================================================== 100 =====================================================>| Time: 00:00:00 

Pending:
  dashboards/show.html.slim add some examples to (or delete) /Users/josh/Documents/Work/Sientia/tests/transition/spec/views/dashboards/show.html.slim_spec.rb
    # No reason given
    # ./spec/views/dashboards/show.html.slim_spec.rb:4
  DashboardsHelper add some examples to (or delete) /Users/josh/Documents/Work/Sientia/tests/transition/spec/helpers/dashboards_helper_spec.rb
    # No reason given
    # ./spec/helpers/dashboards_helper_spec.rb:14
  User add some examples to (or delete) /Users/josh/Documents/Work/Sientia/tests/transition/spec/models/user_spec.rb
    # No reason given
    # ./spec/models/user_spec.rb:4

Finished in 0.30327 seconds
6 examples, 1 failure, 3 pending

Failed examples:

rspec ./spec/controllers/dashboards_controller_spec.rb:6 # DashboardsController GET 'show' returns http success

Randomized with seed 23444

But manually, I can run them:

josh@macbuech:~/Documents/Work/Sientia/tests/transition (features/devise *)$ rspec spec/acceptance/
 2/2 |===================================================== 100 =====================================================>| Time: 00:00:00 

Finished in 0.20759 seconds
2 examples, 0 failures

Randomized with seed 39820

Do I have to add the path somewhere? Or the .feature extension?

Trunip can't handle (some) custom formatters

Note: I posted in the Google Group and jonas mentioned it was a bug, so I am posting it here. Unfortunately, my group cannot use turnip without this functionality, so we will investigate another framework. If anyone knows something I am doing wrong let me know.

What I posted is below:

Hi,

I am attempting to use Turnip with a Rspec rake task, in continuous integration. After using my CI server's built-in Rspec Formatter, I noticed that no examples would be detected. When I run it without the formatter, things would work.

So I went further and tried to use various different JUnit Formatters, as my CI server can use that format instead of using its own Rspec Formatter.

I have made a sample project to replicate this issue. The project structure is as follows:

--sample_rspec
|
--Rakefile
--.rspec (with the single line 'r -turnip/rspec')
--spec
|
--junit.rb (a formatter, i'll explain later)
--sample_feature.feature
--spec_helper.rb
--steps
|
--sample_steps.rb

I have tried using the following formatters:
Gem 'rspec_junit_formatter' (from here)
Gem 'rspec-extra-formatters' (from here)
A file 'junit.rb' to be required in rspec call (from here)
Gem 'ci_reporter' (from here)

My Rakefile:

namespace :sample_rspec do
  require 'rspec/core/rake_task'
  require 'rubygems'
  require 'ci/reporter/rake/rspec'
  require 'time'  

  desc "Run Sample Tests without formatter"
  RSpec::Core::RakeTask.new(:test) do |t|
    t.pattern = './spec/*'
  end

  desc "Run Sample Tests with gem 'rspec_junit_formatter'"
  RSpec::Core::RakeTask.new(:test_rspec_junit_formatter) do |t|
    t.pattern = './spec/*'
    t.rspec_opts =  ["-r rspec_junit_formatter", "-f RspecJunitFormatter", "-o rspec_junit_formatter.xml"]
  end

  desc "Run Sample Tests with gem 'rspec-extra-formatters'"
  RSpec::Core::RakeTask.new(:test_rspec_extra_formatters) do |t|
    t.pattern = './spec/*'
    t.rspec_opts =  ["-r rspec-extra-formatters", "-f JUnitFormatter", "-o rspec-extra-formatters.xml"]
  end  

  desc "Run Sample Tests with file 'junit.rb'"
  RSpec::Core::RakeTask.new(:test_rspec_formatter_from_blog) do |t|
    t.pattern = './spec/*'
    t.rspec_opts =  ["-r ./spec/junit.rb", "-f JUnit", "-o rspec_formatter_from_blog.xml"]
  end

  desc "Run Sample Tests with gem 'ci_reporter'"
  RSpec::Core::RakeTask.new(:test_rspec_ci_reporter => 'ci:setup:rspec') do |t|
    t.pattern = './spec/*'
    t.rspec_opts =  ["-r ./spec/junit.rb", "-f JUnit", "-o rspec_formatter_from_blog.xml"]
  end

end

My sample_feature.feature file:

Feature: Attacking a monster
  Background:
    Given there is a monster

  Scenario: attack the monster
    When I attack it
    Then it should die

My sample_steps file:

step "there is a monster" do
    puts "there is a monster!"
end

step "I attack it" do
    puts "ATTAAAAACK!"
end

step "it should die" do
    puts "it died :("
end

My spec_helper file:

Dir.glob("spec/steps/**/*steps.rb") { |f| load f, true }

So I ran all of the tasks seperately in the RakeFile, and here is the output:

Without a formatter:

My-MacBook-Pro:sample_rspec Me$ rake sample_rspec:test
/Users/Me/.rvm/rubies/ruby-1.9.2-p320/bin/ruby -S rspec ./spec/junit.rb ./spec/sample_feature.feature ./spec/spec_helper.rb ./spec/steps
there is a monster!
ATTAAAAACK!
it died :(
.


Finished in 0.00097 seconds
1 example, 0 failures

With every other formatter:

My-MacBook-Pro:sample_rspec Me$ rake sample_rspec:test_rspec_junit_formatter
/Users/Me/.rvm/rubies/ruby-1.9.2-p320/bin/ruby -S rspec ./spec/junit.rb ./spec/sample_feature.feature ./spec/spec_helper.rb ./spec/steps -r rspec_junit_format
ter -f RspecJunitFormatter -o rspec_junit_formatter.xml
/Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load': /Users/Me/Documents/AbineWork/tmp/sample_rspec
/spec/sample_feature.feature:1: syntax error, unexpected ':', expecting $end (SyntaxError)
Feature: Attacking a monster
        ^
        from /Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
        from /Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `map'
        from /Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:746:in `load_spec_files'
        from /Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:22:in `run'
        from /Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
        from /Users/Me/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'
rake aborted!
/Users/Me/.rvm/rubies/ruby-1.9.2-p320/bin/ruby -S rspec ./spec/junit.rb ./spec/sample_feature.feature ./spec/spec_helper.rb ./spec/steps -r rspec_junit_format
ter -f RspecJunitFormatter -o rspec_junit_formatter.xml failed

Tasks: TOP => sample_rspec:test_rspec_junit_formatter
(See full trace by running task with --trace)

Also note that the formatters worked when I was just using _spec.rb files and straight rspec.

Is there something I am missing?

Line location is wrong when spec is failing

After a failing spec, I have some exceptions displayed, and the handy command to rerun the test if needed:

rspec ./spec/acceptance/company_members.feature:60 #

The problem is: my company_members.feature file has 54 lines, so 60 is wrong.
I've tried with the exact line of the failing scenarion (47), but no spec is found in that case:

Run options: include {:locations=>{"./spec/acceptance/company_members.feature"=>[47]}}  

All examples were filtered out          
  0 examples:  100% |==========================================| Time: 00:00:00 

Finished in 0.00636 seconds
0 examples, 0 failures  

thanks

Tables does not work using JRuby

Hi!

Found the problem that tables does not work using JRuby interpreter. Using them leads to the following error:

ArgumentError: wrong number of arguments (1 for 0)
step at /home//.rvm/gems/jruby-1.7.3@gamification/gems/turnip-1.1.0/lib/turnip/builder.rb:156

This error occurs at:

step.rows.map { |row| row.cells(&:value) }

espescially:

row.cells(&:value)

One possible solution is to use just "to_a" method. This worked for me on JRuby-1.7.3 and on Ruby-1.9.3.

step.rows.map { |row| row.cells.to_a }

forked the code and fixed this issue checking for class of step.rows, see:
https://github.com/runtastic/turnip

Retro-compatibility with Cucumber step definitions (Regexp). Why not?

Hi,

Thanks for Turnip. I think it's a really nice to be able to do the same things as Cucumber in our well-known RSpec environment, so I'm definitely looking into moving from Cucumber to Turnip.

However, before I'm able to say "Yes", let's delete our Cucumber stuff, I'd like to give it a shot without taking hours to rewrite my step definitions (which are Regexps...).

I definitely understand the point of not using Regexp, I just don't want to change tens of step definitions yet. So... why not the possibility to use Regexp in place of strings with placeholders?

I enabled it in this fork here if someone is interested. Currently working on my whole test suite after some adjustments related to Cucumber's step definitions and helpers (should be explained in the README).

Travis CI fails to run features

My specs and acceptance tests run 100% green on my local machine.

When I let Travis CI run them, though, the Turnip acceptance tests fail:

https://travis-ci.org/jmuheim/transition/builds/17069121

/home/travis/build/jmuheim/transition/spec/acceptance/users/confirm_registration.feature:1: syntax error, unexpected ':', expecting end-of-input (SyntaxError)
Feature: Confirm registration
        ^
    from /home/travis/build/jmuheim/transition/vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
    from /home/travis/build/jmuheim/transition/vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
    from /home/travis/build/jmuheim/transition/vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
    from /home/travis/build/jmuheim/transition/vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
    from /home/travis/build/jmuheim/transition/vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'
    from /home/travis/build/jmuheim/transition/vendor/bundle/ruby/2.0.0/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

I have disabled them for a tests, and now the build passes:

https://travis-ci.org/jmuheim/transition/builds/17074697

Do you have any idea why the .feature files cause problems? They somehow seem to be parsed wrong, or they are not recognized as Gherkin.

Thanks for help.

adding -r turnip/rspec to .rspec gives errors

Added turnip to Gemfile, bundle install'd and then copied over a feature from cucumber for the project to spec/acceptance/ directory. However, when I run rspec spec/acceptance/<that_feature_file> I get 'no file to load turnip/rspec'

In Gemfile I have group :test do gem 'turnip' after which I run bundle install

∴ gem list turnip

*** LOCAL GEMS ***

turnip (0.3.1)
∴ cat .rspec
--colour -r turnip/rspec
∴ rspec spec/acceptance/00_can_visit_the_site.feature 
/home/me/.rvm/rubies/ruby-1.9.3-p194/lib64/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- turnip/rspec (LoadError)
    from /home/me/.rvm/rubies/ruby-1.9.3-p194/lib64/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:402:in `block in requires='
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:402:in `map'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/configuration.rb:402:in `requires='
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/configuration_options.rb:19:in `block in configure'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/configuration_options.rb:18:in `each'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/configuration_options.rb:18:in `configure'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/command_line.rb:21:in `run'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:69:in `run'
    from /home/me/.rvm/gems/ruby-1.9.3-p194@pmp/gems/rspec-core-2.9.0/lib/rspec/core/runner.rb:10:in `block in autorun'

I expected to see pending reported for steps since I have none defined, but not that it couldn't find the RSpec stuff. :-)

Allow to run a specific scenario by the line number

Would be great to turnip support line filters like normal specs:

rspec spec/acceptance/property_negative_certificate.feature:10

Currently the RSpec exists saying there is no specs in the given line regardless the number of the line.

Error when spec_helper.rb file doesn't exist

When running Turnip, an error is thrown if spec_helper.rb file doesn't exist:


 rspec spec
/Users/alscott/.rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require': cannot load such file -- spec_helper (LoadError)
    from /Users/alscott/.rvm/rubies/ruby-1.9.3-rc1/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:55:in `require'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/turnip-0.2.0/lib/turnip/loader.rb:5:in `load'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `block in load_spec_files'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `map'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:in `load_spec_files'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:in `run'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_in_process'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
    from /Users/alscott/.rvm/gems/ruby-1.9.3-rc1@turnip/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block in autorun'

Upgrading to turnip v1.1.0 causes support modules not to load

We have a Rails 3.2 app. We upgraded to turnip 1.1 and all of our acceptance tests broke. The errors are all related to undefined local variables or methods that are defined in support modules located in the spec/support folder.

When we change our Gemfile to explicitly declare turnip v 1.0 and rebundle, the acceptance tests pass again with no other changes to the codebase required.

Choose acceptance type instead of turnip

Hi @jnicklas,

Currently capybara have this configuration:

config.include Capybara::DSL, :type => :request
config.include Capybara::DSL, :type => :acceptance
config.include Capybara::RSpecMatchers, :type => :request
config.include Capybara::RSpecMatchers, :type => :acceptance

And on turnip:

Turnip.type = :turnip

And on turnip/capybara:

Turnip.type = :request

And turnip readme suggests to use a folder named acceptance, like spec/acceptance/attack_monster.feature.

Do not make more sense call the turnip specs as acceptance specs instead of turnip specs in one situation and request specs in other situation?

That's not a big deal but caused a lot of confusion in my mind until I setup one real application because I have specific steps, like this one:

module CustomersSteps
  ...
end

RSpec.configure do |config|
  # my first guess:
  config.include CustomerSteps, :type => :acceptance

  # but without capybara is:
  config.include CustomerSteps, :type => :turnip

  # and with capybara is:
  config.include CustomerSteps, :type => :request
end

Calling turnip specs always as acceptance specs will include capybara by default if it's available.

I think that will be a good thing since I will not need to setup turnip to integrate with capybara on every project :)

If capybara isn't available, nothing will happen, the turnip specs will continue to be called acceptance specs.

WDYT?

Documentation: Calling steps from other steps

Hej,

if I'm not missing anything, there is documentation missing for the "calling steps from other steps" feature of Turnip 0.3.0 (thanks @leshill ).

If you want some docs for this feature I would give it a go this week - I would put it in the README under reusing steps or in a separate section - what do you think?

Thanks for Turnip and cheers,
Tobias

Remove multiple tags on steps_for?

Currently the steps_for DSL allows you to specify multiple tags on a single module. Here is the syntax that would be used:

steps_for :foo, :bar do
end

I don't think there's much of a use-case anymore for being able to specify multiple tags anymore. With the use_steps feature it seems like you can pretty much fine-tune everything that way via module inclusion.

If you have a module that you would like to use in multiple places, you can just use its steps in both places' step modules.

I guess one possible use-case is a feature that does not have its own steps_for using only :global? Even at that point you still wouldn't need to specify multiple tags on the steps_for call, you'd just include the one tag on your feature.

It's also possible I just haven't run across the correct use-case in my use of Turnip so far.

Are rspec stups supported in steps?

I wan't to stup a function in my ApplicationController

ApplicationController.rb:

class ApplicationController < ActionController::Base
...
def set_currency
  currency = AppConfig.currency || 'CHF'
end  
...

AdministrationController.rb:

class AdministrationController < ApplicationController
...
def pools
  @currency = set_currency
  @pools = Pool.order(:hdvm_pool_id, :storage_array_id).all
end
...

currency_steps.rb:

step 'It should display the price with currency FF' do
  ApplicationController.any_instance.stub(:set_currency).and_return('FF')
  page.should have_content('FF')
end

The result is always 'CHF', and never the expected result of 'FF'

undefined method 'placeholder' for Turnip::Steps::Module

Hey!

looks like our placeholders aren't working with the 1.0.0 release.

we define them with:

steps_for :banners do
  step 'I fill in :banner_count :banner_type banner/banners' do |banner_count, banner_type|
    banner_count.times do |i|
      within "li.list:nth-of-type(#{i+1})" do
        fill_in 'Link', :with => "http://example.com"
        case banner_type
        when 'retina'
          attach_file "iPad Retina Banner Image", "spec/fixtures/files/valid_2x_banner.jpg"
        when 'standard'
          attach_file "iPad Banner Image", "spec/fixtures/files/valid_banner.jpg"
        end
      end
    end
  end

  placeholder :banner_count do
    match(/\d+/)      { |i| i.to_i }
    match(/another/)  { 2 }
    match(/a/)        { 1 }
  end
end

then when we load our steps we get the following error:


spec/acceptance/steps/banner_steps.rb:21:in `<module:Steps>': undefined method `placeholder' for Turnip::Steps:Module (NoMethodError)
    from spec/acceptance/steps/banner_steps.rb:1:in `<top (required)>'
    from /Users/denro/.rvm/gems/ruby-1.9.2-p320@serviceplus/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
    from /Users/denro/.rvm/gems/ruby-1.9.2-p320@serviceplus/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `block in load'
    from /Users/denro/.rvm/gems/ruby-1.9.2-p320@serviceplus/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Users/denro/.rvm/gems/ruby-1.9.2-p320@serviceplus/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:245:in `load'
    from /Users/denro/workspace/serviceplus/spec/support/turnip_steps_loader.rb:2:in `block in <top (required)>'
    from /Users/denro/workspace/serviceplus/spec/support/turnip_steps_loader.rb:2:in `glob'
    from /Users/denro/workspace/serviceplus/spec/support/turnip_steps_loader.rb:2:in `<top (required)>'

Better debug information?

I'm currently evaluating Turnip and I'm really liking it so far. Good job Jonas!

Of course, I'm comparing it to the flow I had with Cucumber. I really don't miss the regular expressions, but I do miss some of the debug information you get with Cucumber:

  1. When a test fails I would like to know what step failed (Feature filename and line number, and step definition file and line number)

  2. When a step is not implemented do an implementation suggestion

  3. To a lesser degree I miss the verbose mode where a feature is being printed when you run it (I like that for WIP features).

Is any of these being worked on? I hacked 2) together, but 1) is a bit harder I believe, but really important IMHO.

Cheers,
Jeroen

turnip/capybara problems

I'm having a bit of trouble running my turnip features. Specifically, I'm getting the following error:

1) Searching Searching by term, no results found
  Failure/Error: Turnip::ScenarioRunner.new(self).load(Turnip::ScenarioContext.new(feature, scenario)).run
  NoMethodError:
    undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fa9326da7f8>
  # spec/step_definitions/customers/searches_steps.rb:2:in `block in <top (required)>'

My spec_helper:

require File.expand_path("../spec/dummy/config/environment", __FILE__)

require "turnip/capybara"

RSpec.configure do |config|
  config.treat_symbols_as_metadata_keys_with_true_values = true
  config.run_all_when_everything_filtered = true
  config.filter_run :focus

  Turnip::Config.step_dirs = 'spec/step_definitions'
  Turnip::StepLoader.load_steps
end

My spec/features/customers/search.feature:

Scenario: Searching by term, no results found
  When I visit the customer search page
  And I search for "albion heights"
  Then I should see "No results found"

And finally my spec/step_definitions/customers/searches_steps.rb:

step "I visit the customer search page" do
  visit "/searches" # temp path
end

Any ideas? I'm sure I'm missing a configuration line!

Cheers

Gav

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.