GithubHelp home page GithubHelp logo

cucumber / cucumber-rails Goto Github PK

View Code? Open in Web Editor NEW
1.0K 100.0 329.0 1.79 MB

Rails Generators for Cucumber with special support for Capybara and DatabaseCleaner

Home Page: https://github.com/cucumber/cucumber-rails

License: MIT License

Ruby 50.40% HTML 6.95% Gherkin 41.74% Shell 0.91%
polyglot-release rails ruby tidelift

cucumber-rails's Introduction

Cucumber-Rails

Gem Version build Code Climate Open Source Helpers

Cucumber-Rails brings Cucumber to Rails 5.2, 6.x and 7.x.

Installation

Before you can use the generator, add the gem to your project's Gemfile as follows:

group :test do
  gem 'cucumber-rails', require: false
  # database_cleaner is not required, but highly recommended
  gem 'database_cleaner'
end

Then install it by running:

bundle install

Learn about the various options:

rails generate cucumber:install --help

Finally, bootstrap your Rails app, for example:

rails generate cucumber:install

Running Cucumber

[bundle exec] cucumber

Configuration options

By default, cucumber-rails runs DatabaseCleaner.start and DatabaseCleaner.clean before and after your scenarios. You can disable this behaviour like so:

# features/support/env.rb
# ...
Cucumber::Rails::Database.autorun_database_cleaner = false

By default, cucumber-rails will auto mix-in the helpers from Rack::Test into your default Cucumber World instance. You can prevent this behaviour like so:

# features/support/env.rb
ENV['CR_REMOVE_RACK_TEST_HELPERS'] = 'true'

Upgrading from a previous version

When upgrading from a previous version it is recommended that you rerun:

rails generate cucumber:install

Bugs and feature requests

The only way to have a bug fixed or a new feature accepted is to describe it with a Cucumber feature. Let's say you think you have found a bug in the cucumber:install generator. Fork this project, clone it to your workstation and check out a branch with a descriptive name:

git clone [email protected]:you/cucumber-rails.git
git checkout -b bugfix/generator-fails-on-bundle-exec

Start by making sure you can run the existing features. Now, create a feature that demonstrates what's wrong. See the existing features for examples. When you have a failing feature that reproduces the bug, commit, push and send a pull request. Someone from the Cucumber-Rails team will review it and hopefully create a fix.

If you know how to fix the bug yourself, make a second commit (after committing the failing feature) before you send the pull request.

Setting up your environment

Make sure you have a supported ruby installed, cd into your cucumber-rails repository and run

gem install bundler
bundle install
bin/install_geckodriver.sh
bin/install_webpacker.sh

Running all tests

With all dependencies installed, all specs and features should pass:

[bundle exec] rake

Running Appraisal suite

In order to test against multiple versions of key dependencies, the Appraisal gem is used to generate multiple gemfiles, stored in the gemfiles/ directory. Normally these will only run on GitHub via GitHub Actions; however if you want to run the full test suite against all gemfiles, run the following commands:

[bundle exec] appraisal install
[bundle exec] appraisal rake test

To run the suite against a named gemfile, use the following:

[bundle exec] appraisal rails_6_0 rake test

Adding dependencies

To support the multiple-gemfile testing, when adding a new dependency the following rules apply:

  1. If it's a runtime dependency of the gem, add it to the gemspec
  2. If it's a primary development dependency, add it to the gemspec
  3. If it's a dependency of a generated rails app in a test, add it to the helper method that modifies the Gemfile

For example, rspec is a primary development dependency, so it lives in the gemspec.

cucumber-rails's People

Contributors

alg avatar aslakhellesoy avatar aurelien-reeves avatar bjeanes avatar chaffeqa avatar davebrace avatar deivid-rodriguez avatar drogus avatar felixbuenemann avatar gnandretta avatar gobijan avatar koic avatar kosmas avatar kotovalexarian avatar langalex avatar luke-hill avatar mathieujobin avatar mattwynne avatar mgrunberg avatar msassak avatar mvz avatar olleolleolle avatar orien avatar rafamanzo avatar sferik avatar stevehodgkiss avatar tooky avatar twalpole avatar utkarsh2102 avatar xtrasimplicity 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  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

cucumber-rails's Issues

cucumber:feature and integers. not createing feature correctly

when I run ruby script/rails generate cucumber:feature Asset serial_number:string asset_type_id:integer

in my manage_assets.feature file I get

Scenario: Register new asset
Given I am on the new asset page
When I fill in "Serial number" with "serial_number 1"
And I fill in "Asset type" with "asset_type_id 1"
And I press "Create"
Then I should see "serial_number 1"

And I should see "asset_type_id 1"

Scenario: Delete asset
Given the following assets:
|serial_number|asset_type_id|
|serial_number 1|asset_type_id 1|
|serial_number 2|asset_type_id 2|
|serial_number 3|asset_type_id 3|
|serial_number 4|asset_type_id 4|
When I delete the 3rd asset
Then I should see the following assets:
|Serial number|Asset type|
|serial_number 1|asset_type_id 1|
|serial_number 2|asset_type_id 2|
|serial_number 4|asset_type_id 4|

when it should be

Scenario: Register new asset
Given I am on the new asset page
When I fill in "Serial number" with "serial_number 1"
And I fill in "Asset type" with "1"
And I press "Create"
Then I should see "serial_number 1"

And I should see "1"

Scenario: Delete asset
Given the following assets:
|serial_number|asset_type_id|
|serial_number 1| 1|
|serial_number 2| 2|
|serial_number 3| 3|
|serial_number 4| 4|
When I delete the 3rd asset
Then I should see the following assets:
|Serial number |Asset type|
|serial_number 1| 1|
|serial_number 2| 2|
|serial_number 4| 4|

in my gemfile


group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'cucumber-rails'
gem 'cucumber', '0.7.2'
gem 'rspec-rails', '2.0.0.beta.8'
gem 'spork'
gem 'launchy' # So you can do Then show me the page
end


I bootstrapped using . . .
ruby script/rails generate cucumber:skeleton --rspec --capybara
running rails -v 3.0.0.beta3
ruby -v ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]

I'm really new to git so I'm really sure to to make a branch try my fix and resubmit it. and still green with ruby. . .
but in looking at the source on http://github.com/aslakhellesoy/cucumber-rails/blob/master/templates/feature/feature.erb

I was wondering if line 12 adding

<% elsif arg.type == 'integer' -%>
<%= keyword %> I fill in "<%= arg.name.humanize %>" with "1"

not really sure how to handle the "delete" section...

Any way maybe someone with more experience can fix it or where can I learn how to branch, try, test a patch, submit it and all that jazz.

John Ivanoff
http://github.com/johnivanoff

!host ignored in steps in Rails 3

I'm trying to test some subdomain functionality in a Rails3 app and have used the following in a step:

Given /^I visit subdomain (.+)$/ do |sub|
  host! "#{sub}.local"
end

I'm not 100% sure if this is an issue, but within my app I'm testing for existence of a subdomain (and printing it out for testing) and only seeing 'www' returned during requests when the step above is called at the start of a story.

Is this a symptom of Cucumber/Cucumber-rails/Rspec using a new integration approach (have had some issues with controller testing in rspec)?

Features fail after upgrading from rails 2.3.5 to 2.3.8

Hi,

I have upgraded rails (= changed RAILS_GEM_VERSION = '2.3.8' in environment.rb file), and now a lot of features don't pass anymore.
Apparently, the step :

When I sign out

which is basically :

When /^I sign out$/ do
  When %{I go to the sign out page}
end

Don't sign me out (flash is not set, and the page in output still shows user's account info. We're using devise 1.0.7 for authentication.
thanks

(ps : I'm just creating the ticket to see if others have the same issue for now)

should present consistent vocabulary for radio buttons

The 'I check "foo"' step definition applies exclusively to checkboxes, and the 'I choose "foo"' step definition exclusively to radio buttons.

But the 'the "foo" checkbox should/should not be checked" step definition applies to radio buttons as well as checkboxes. Instead it should apply exclusively to checkboxes, and a step definition for 'the "foo" radio button should be chosen' should be provided exclusively for radio buttons.

Separate web steps for being on a page and checking query string params

In issue #5, verification of query string params was added to the step for being on a page. Checking that I'm simply on a page feels like the most common case to me. Checking query string params feels like it should be an optional, extra step. Therefore, revert the change for issue #5, and make checking query string params its own step. What was proposed on the mailing list,


Then I should have the following query string:
 |version|7|
 |count|10|
 |lang|en|

would be fine.

Unable to run 'rake cucumber' with unpacked gherkin gem

Environment:

Mac OS X Darwin Kernel Version 10.4.0
ruby, version 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] 
rails, version 2.3.8 
rubygems, version 1.3.7 
rake, version 0.8.7 

in my config/environments/test.rb

# rspec, cucumber
config.gem "rspec", :lib => false, :version => ">=1.3.0" 
config.gem "rspec-rails", :lib => false, :version => ">=1.3.2" 
config.gem "webrat", :lib => false, :version => ">=0.7.1" 
config.gem "cucumber-rails", :lib => false, :version => ">=0.3.2" 
config.gem "gherkin", :version => ">=2.0.2"
$ gem list --local 
*** LOCAL GEMS *** 
actionmailer (2.3.8, 2.3.5, 1.3.6) 
actionpack (2.3.8, 2.3.5, 1.13.6) 
actionwebservice (1.2.6) 
activerecord (2.3.8, 2.3.5, 1.15.6) 
activeresource (2.3.8, 2.3.5) 
activesupport (2.3.8, 2.3.5, 1.4.4) 
acts_as_ferret (0.4.3) 
authlogic (2.1.3) 
builder (2.1.2) 
capistrano (2.5.2) 
cgi_multipart_eof_fix (2.5.0) 
cucumber (0.8.3) 
cucumber-rails (0.3.2) 
daemons (1.0.10) 
dancroak-validates_email_format_of (1.2.2) 
database_cleaner (0.5.2) 
diff-lcs (1.1.2) 
dnssd (0.6.0) 
faker (0.3.1) 
fastthread (1.0.1) 
fcgi (0.8.7) 
ferret (0.11.6) 
gem_plugin (0.2.3) 
gemcutter (0.5.0) 
gherkin (2.0.2) 
git (1.2.5) 
highline (1.5.0) 
hpricot (0.6.164) 
jeweler (1.4.0) 
json (1.4.3) 
json_pure (1.4.3) 
libxml-ruby (1.1.2) 
memcache-client (1.8.3) 
mislav-will_paginate (2.3.11) 
mocha (0.9.8) 
mongrel (1.1.5) 
needle (1.3.0) 
net-scp (1.0.1) 
net-sftp (2.0.1, 1.1.1) 
net-ssh (2.0.4, 1.1.4) 
net-ssh-gateway (1.0.0) 
nokogiri (1.4.2) 
passenger (2.2.11) 
pg (0.9.0) 
postgres-pr (0.6.3) 
prawn (0.8.4) 
prawn-core (0.8.4) 
prawn-layout (0.8.4) 
prawn-security (0.8.4) 
rack (1.1.0, 1.0.1) 
rack-test (0.5.4) 
rails (2.3.8, 2.3.5, 1.2.6) 
rake (0.8.7, 0.8.3) 
rbench (0.2.3) 
RedCloth (4.1.1) 
rspec (1.3.0) 
rspec-rails (1.3.2) 
ruby-ole (1.2.10.1) 
ruby-openid (2.1.2) 
ruby-prof (0.8.1) 
ruby-yadis (0.3.4) 
rubyforge (2.0.4) 
rubygems-update (1.3.7) 
rubynode (0.1.5) 
spreadsheet (0.6.4.1) 
sqlite3-ruby (1.2.4) 
term-ansicolor (1.0.5) 
termios (0.9.4) 
text-format (1.0.0) 
text-hyphen (1.0.0) 
tmail (1.2.7.1) 
trollop (1.16.2) 
tzinfo (0.3.20) 
webrat (0.7.1) 
xmpp4r (0.4)
$ rake cucumber 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I 
"/Library/Ruby/Gems/1.8/gems/cucumber-0.8.3/lib:lib" "/Library/Ruby/ 
Gems/1.8/gems/cucumber-0.8.3/bin/cucumber"  --profile default 
Using the default profile... 
.................................. 
4 scenarios (4 passed) 
34 steps (34 passed) 
0m1.222s 
$ rake gems:unpack:dependencies RAILS_ENV=test 
Unpacked gem: '/Users/john/project/vendor/gems/rspec-1.3.0' 
Unpacked gem: '/Users/john/project/vendor/gems/rspec-rails-1.3.2' 
Unpacked gem: '/Users/john/project/vendor/gems/webrat-0.7.1' 
Unpacked gem: '/Users/john/project/vendor/gems/nokogiri-1.4.2' 
Unpacked gem: '/Users/john/project/vendor/gems/rack-test-0.5.4' 
Unpacked gem: '/Users/john/project/vendor/gems/cucumber-rails-0.3.2' 
Unpacked gem: '/Users/john/project/vendor/gems/cucumber-0.8.3' 
Unpacked gem: '/Users/john/project/vendor/gems/gherkin-2.0.2' 
Unpacked gem: '/Users/john/project/vendor/gems/trollop-1.16.2' 
Unpacked gem: '/Users/john/project/vendor/gems/term-ansicolor-1.0.5' 
Unpacked gem: '/Users/john/project/vendor/gems/diff-lcs-1.1.2' 
$ sudo gem uninstall gherkin 
$ rake gems:build 
Built gem: '/Users/john/project/vendor/gems/gherkin-2.0.2' 
Built gem: '/Users/john/project/vendor/gems/nokogiri-1.4.2' 
$ rake cucumber 
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -I 
"/Users/john/project/vendor/gems/cucumber-0.8.3/lib:lib" "/Users/john/ 
project/vendor/gems/cucumber-0.8.3/bin/cucumber"  --profile default 
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in 
`gem_original_require': no such file to load -- gherkin (LoadError) 
        from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in 
`require' 
        from /Users/john/project/vendor/gems/cucumber-0.8.3/bin/../lib/ 
cucumber/cli/main.rb:5 
        from /Users/john/project/vendor/gems/cucumber-0.8.3/bin/cucumber:5:in 
`require' 
        from /Users/john/project/vendor/gems/cucumber-0.8.3/bin/cucumber:5 
rake aborted! 
Command failed with status (1): [/System/Library/Frameworks/ 
Ruby.framework/...] 
(See full trace by running task with --trace) 

If I reinstall the gherkin gem everything is back to normal.

I've also tried using the script/cucumber to see if it is rake specific.

$ ruby script/cucumber 
/Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in 
`gem_original_require': no such file to load -- gherkin (LoadError) 
        from /Library/Ruby/Site/1.8/rubygems/custom_require.rb:31:in 
`require' 
        from /Users/john/project/vendor/gems/cucumber-0.8.3/bin/../lib/ 
cucumber/cli/main.rb:5 
        from /Users/john/project/vendor/gems/cucumber-0.8.3/bin/cucumber:5:in 
`require' 
        from /Users/john/project/vendor/gems/cucumber-0.8.3/bin/cucumber:5 
        from script/cucumber:5:in `load' 
        from script/cucumber:5 

However, specifying the lib path seems to clear up the problem.

$ ruby -Ivendor/gems/gherkin-2.0.2/lib script/cucumber 
Using the default profile... 
.................................. 
4 scenarios (4 passed) 
34 steps (34 passed) 
0m1.309s 

Here is a workaround!

Modify vendor/gems/cucumber-0.8.3/lib/cucumber/rake/task.rb and add a hardcoded path for the gherkin libraries:

class ForkedCucumberRunner #:nodoc: 
        attr_reader :args 
        def initialize(libs, cucumber_bin, cucumber_opts, feature_files) 
          libs.unshift("#{Rails.root}/vendor/gems/gherkin-2.0.2/lib") 
          @args = ( 
            ['-I'] + load_path(libs) + 
            quoted_binary(cucumber_bin) + 
            cucumber_opts + 
            feature_files 
          ).flatten 
        end 

gem 'launchy' cannot be installed w rails3.rc and ruby-1.9.2.rc1

I upgraded my testApp this morning ...
I modified the Gemfile :
gem 'rails', '>=3.0.0.rc'

but then (confirmed w another test app) got the error :

~/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/rubygems/package/tar_input.rb:111:in `initialize': No metadata found! (Gem::Package::FormatError)

Rspec::Matchers renamed to RSpec::Matchers

In rspec2.0.0.beta.9 the Rspec namespace has been renamed to RSpec AFAICT. Row 8 in lib/cucumber/rails/rspec.rb should be changed from
include Rspec::Matchers
to
include RSpec::Matchers
otherwise cucumber steps are unhappy as soon as they try to use rspec matchers.

action_controller/test_process

When I tried cucumber-rails following the guide of README, at last I used:

rake cucumber

I got:

no such file to load -- action_controller/test_process (LoadError)

Any help is appreciated.

Running test/unit tests when creating a skeleton

When we create a skeleton with "script/rails g cucumber:skeleton" the test suite is started because of the way rspec/test-unit presence is checked. It appears, tests are automatically triggered by requiring the "test/unit" even if you don't do anything else.

Maybe Gem.available?(...) is a better choice? But on the other hand, even though it returns true for "rspec" from irb, it doesn't do that from the code and also totally ignores "test/unit". Weird.

RSpec::Matchers not enough to include for RSpec 2

lib/cucumber/rails/rspec.rb just includes RSpec::Matchers, but I believe cucumber-rails --rspec relies on rspec-rails' redirect_to and render_template matchers. These need to be included manually, ex:

[Cucumber::Rails::World, ActionController::Integration::Session].each do |klass|
  klass.class_eval do
    include RSpec::Matchers
    include RSpec::Rails::Matchers::RedirectTo
    include RSpec::Rails::Matchers::RenderTemplate
  end
end

Note that just including RSpec::Rails::Matchers won't do it.

I just have that lying around in my env.rb for now, and note that I also had to include Webrat::Matchers for have_selector (which is replacing rspec-rails' have_tag). Still don't have my features running after the upgrade, but thought I'd point this out.

tableish returns no content for a cell containing html img

lib/cucumber/web/tableish.rb, line 99: cell.text.strip

When a table cell only contains an html img, "cell.text" will return an empty string. Changing this to cell.inner_html will correctly return the table cell content.

My setup:
Ruby 1.8.7
cucumber-rails 1.3.1
cucumber 0.7.3
webrat 0.7.1
nokogiri 1.4.1

would like table.raw

It would be nice if Cucumber::Ast::Table could return the raw array of arrays (rather than the array of hashes).

I just changed line 55 of ast/table.rb

from
attr_accessor :file
to
attr_accessor :file, :raw

Here is how I would like to use it.
Given /^there is a file "([^\"]*)" that looks like:$/ do |file_name, table|
f = File.open("#{file_name}", 'w')
out = ""
table.raw.each do |row|
out += row.join("\t")
out += "\n"
end
f.write(out)
f.close
end

cucumber.rake finds the wrong vendored cucumber when a plugin name starts with "cucumber"

In my project I have installed the plugin http://github.com/mischa/cucumber_rails_debug/

When I run "rake cucumber" it assumes that cucumber is installed in vendor/plugins/cucumber_rails_debug

This is because of line 1 in cucumber.rake:

vendored_cucumber_dir = Dir["#{RAILS_ROOT}/vendor/{gems,plugins}/cucumber*"].first

Possible strategies could be:

  • Don't use the ending * when searching in vendor/plugins, use it only for vendor/gems
  • Perform an additional check for the existence of file bin/cucumber inside the folder.

Hope it'll help,
Paco.

@culerity tag breaks Rails 3 RESTful helpers

Using a capybara skeleton, if I tag the default Delete Scenario with @culerity instead of @emulate_rails_javascript, using the RESTful helper in 'visit posts_url' directs Culerity to go to "http://www.example.com/posts" which gives me a 404 and the Scenario fails. However, @emulate_rails_javascript properly goes to "http://localhost:9887/posts" and the Scenario passes. If I replace "visit posts_url" with "visit '/posts'", Culerity goes to the right host, but it still fails the Scenario because it, sadly, cannot follow the new Rails 3 UJS hrefs.

I think posts_url.to_str is throwing me off trying to find out who's fault this is, because whenever I puts/print/p posts_url in my step definition, I always get "http://www.example.com/posts".

I have been trying to figure out exactly where this comes from without any luck so I am not sure if this is a cucumber-rails issue or somewhere else in the capybara->culerity->celerity chain.

clean up database for mongoid

i tested features using cucumber in rails3 application having mongodb/monid database. i have following in background

Background:
Given the following users:
| first_name | last_name | email | password | password_confirmation | role |
| Ram | Limbu | [email protected] | 123456 | 123456 | admin |
| Krishna | Shilpakar | [email protected] | 111111 | 111111 | manager |
| Gagan | Shrestha | [email protected] | 222222 | 222222 | employee |
| Sanjeev | KC | [email protected] | 222222 | 222222 | employee |

when i run cucumber, i got following error:

Validation Failed: Email is already taken (Mongoid::Errors::Validations)
./features/step_definitions/user_steps.rb:3:in block (2 levels) in <top (required)>' ./features/step_definitions/user_steps.rb:2:ineach'
./features/step_definitions/user_steps.rb:2:in /^the following users:$/' features/manage_users.feature:7:inGiven the following users:'

i think there is no database clean up before running each cucumber test. please give me any solution for such problem

ANDing instead of ORing tags for transactional_fixtures

Hi Aslak,

I believe the following code from cucumber-rails/lib/cucumber/rails/active_record.rb is incorrect:

Before('~@no-txn', '~@selenium', '~@culerity', '~@javascript') do
  Cucumber::Rails::World.use_transactional_fixtures = $__cucumber_global_use_txn
end

Before('@no-txn', '@selenium', '@culerity', '@javascript') do
  Cucumber::Rails::World.use_transactional_fixtures = false
end

And that it hasn't been updated post the reversal of the logical behaviour of tags with cucumber 0.6.0. The above now performs a logical AND whereas I believe it is meant to represent a logical OR instead. The revised code should be:

Before('~@no-txn,~@selenium,~@culerity,~@javascript') do
  Cucumber::Rails::World.use_transactional_fixtures = $__cucumber_global_use_txn
end

Before('@no-txn,@selenium,@culerity,@javascript') do
  Cucumber::Rails::World.use_transactional_fixtures = false
end

Admittedly, I haven't actually tried making this change yet to verify (took me ages to figure out why my @sphinx scenarios weren't running in a non-transaction). Not sure what affect this would have any the rest of cucumber-rails and I wasn't clear on whether this change needed to have a feature written for it and where that would go (no features inside cucumber-rails). I figured this was a straightforward change that was simply overlooked with the 0.6.0 changes.

Generated "Then I should see JSON" step fails with capybara

cucumber-0.7.3
rails-2.3.5
script/generate cucumber --capybara

generates ...

# in features/step_definitions/web_steps.rb

Then /^(?:|I )should see JSON:$/ do |expected_json|
  require 'json'
  expected = JSON.pretty_generate(JSON.parse(expected_json))
  actual   = JSON.pretty_generate(JSON.parse(response.body))
  expected.should == actual
end

The third line causes this error:

undefined method `generate' for # (NoMethodError)
./features/step_definitions/web_steps.rb:102:in `__instance_exec0'
./config/../lib/shared/extensions/core/object_extension.rb:31:in `send':in `/^(?:|I )should see JSON:$/'

So I changed the implementation to this:

Then /^(?:|I )should see JSON:$/ do |expected_json|
  require 'json'
  expected = JSON.parse(expected_json)
  actual   = JSON.parse(response.body)
  expected.should == actual
end

And then the error changed to:

undefined method `body' for nil:NilClass (NoMethodError)
./features/step_definitions/web_steps.rb:103:in `__instance_exec0'
./config/../lib/shared/extensions/core/object_extension.rb:31:in `send':in `/^(?:|I )should see JSON:$/'

Then I changed response.body to page.body and all was well.

Error with cucumber 0.7.2 and gherkin 1.0.24: no such file to load -- gherkin/c_lexer

After install cucumber 0.7.2 and cucumber-rails 0.3.1 I have error:

cucumber features/


Using the default profile...
WARNING: no such file to load -- gherkin/c_lexer. Reverting to Ruby lexer. (RuntimeError)
/usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/i18n.rb:106:in rescue in lexer' /usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/i18n.rb:103:inlexer'
/usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:118:in transition_table' /usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:107:inbuild_transition_map'
/usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:103:in transition_map' /usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:70:ininitialize'
/usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:47:in new' /usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:47:inpush_machine'
/usr/lib/ruby/gems/1.9.1/gems/gherkin-1.0.24/lib/gherkin/parser/parser.rb:19:in initialize' /usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/feature_file.rb:31:innew'
/usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/feature_file.rb:31:in parse' /usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/step_mother.rb:62:inblock in load_plain_text_features'
/usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/step_mother.rb:60:in each' /usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/step_mother.rb:60:inload_plain_text_features'
/usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/cli/main.rb:55:in execute!' /usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/lib/cucumber/cli/main.rb:25:inexecute'
/usr/lib/ruby/gems/1.9.1/gems/cucumber-0.7.2/bin/cucumber:8:in <top (required)>' /usr/bin/cucumber:19:inload'
/usr/bin/cucumber:19:in `'

I was trying to create new rails app. It is ok (cucumber features work) before I create first feature. After It the error was appeared.

OS: Arch linux

Rails: 3.0.0.beta.3
Ruby: ruby 1.9.1p378 (2010-01-10 revision 26273) [x86_64-linux]
cucumber (0.7.2)
cucumber-rails (0.3.1)
gherkin (1.0.24)

Gemfile:


gem 'rails', '3.0.0.beta3'
gem 'devise', '1.1.rc1'
group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'rspec-rails', '>=2.0.0.beta.8'
gem 'rspec', '>=2.0.0.beta.8'
gem 'test-unit'
gem 'cucumber', '>=0.7.2'
gem 'cucumber-rails', '0.3.1'#, :git => 'git://github.com/aslakhellesoy/cucumber-rails.git'
gem 'autotest'
gem 'autotest-rails-pure'
gem 'autotest-growl'
gem "factory_girl", :git => "git://github.com/thoughtbot/factory_girl.git", :branch => "rails3"
end

result of:

gem uninstall -aI gherkin
gem install -V gherkin > install_gherkin.txt

http://gist.github.com/389893

Very strange situation:
irb

irb(main):001:0> require 'gherkin/c_lexer'
=> true

But rails console:

rails c
Loading development environment (Rails 3.0.0.beta3)
irb(main):002:0> require 'gherkin/c_lexer'
LoadError: no such file to load -- gherkin/c_lexer
from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in require' from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:inblock in require'
from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:195:in block in load_dependency' from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:523:innew_constants_in'
from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:195:in load_dependency' from /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:inrequire'
from (irb):2
from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta3/lib/rails/commands/console.rb:47:in start' from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta3/lib/rails/commands/console.rb:8:instart'
from /usr/lib/ruby/gems/1.9.1/gems/railties-3.0.0.beta3/lib/rails/commands.rb:34:in <top (required)>' from script/rails:9:inrequire'
from script/rails:9:in `'

Same when I tru to use "RAILS_ENV=test rails c".

It's not only my issue, other people have the same: http://groups.google.com/group/cukes/browse_thread/thread/ed2f0504a0ee8f0b

P.S. I post issue to gherkin issues, but they can't help with bug: http://github.com/aslakhellesoy/gherkin/issues#issue/57

env.rb and world.rb fail in Rails 3 projects

Been trying to make cucumber-rails work with rails 3

In a rails 3 project after running

$ script/generate cucumber:skeleton
It generates a skeleton directory/file structure, with env.rb etc.

I try to run all features and get error in world.rb line 18

$ cucumber features
/Users/kristianconsult/.gem/ruby/1.9.1/gems/cucumber-rails-0.2.5/lib/cucumber/rails/world.rb:18:in `'

using the 'support/env.rb' below trying to resolve rails 3 dependencies

require 'cucumber/formatter/unicode'
require 'rails'
require 'test/unit'
require 'active_support/core_ext/module/attr_internal'
require 'action_view/template'
require 'active_support/test_case'
require 'action_controller'

if I insert this, the line below in world.rb will cause error :(
require 'cucumber/rails/world'

all the above require statements have been an attempt to fix this. This is dependency jungle!!!

This is line 18 in world.rb causing the frustration

require 'action_dispatch/testing/integration'

Could someone please create a new env.rb and world.rb that works with rails 3.0.0.beta1
Thanks!

Don't depend on DatabaseCleaner

Please remove database cleaner calls when it is not avaialable in: lib/cucumber/rails/active_record.rb

If i turn off transaction fixtures i get:

uninitialized constant DatabaseCleaner (NameError)
.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in `load_missing_constant'
.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in `const_missing'
.gem/ruby/1.8/gems/cucumber-rails-0.2.3/lib/cucumber/rails/active_record.rb:18:in `Before'

The "I should be on ..." step definition for webrat needs to handle all types of URIs

The current step definition for the "Then I should be on..." step uses (for webrat) the URI#path method. Previously this was changed to use #request_uri instead, which resolved the issue with the query string not being used in comparisons.

At some point this regressed, however even this change is insufficient because after a "When I follow ..." step the current_url variable contains a relative URL, causing URI.parse to return a URI::Generic object instead of a URI::HTTP object; the former does not implement the #request_uri method. Below is the clunky code I'm using to work around this:

Then /^(?:|I )should be on (.+)$/ do |page_name|
  # Locally patched, replacing #path with #request_uri and then custom implementation.
  current_path = URI.parse(current_url).select(:path, :query).compact.join('?')
  if defined?(Spec::Rails::Matchers)
    current_path.should == path_to(page_name)
  else
    assert_equal path_to(page_name), current_path
  end
end

Change rails 2 environment/cucumber to enable Rails CSRF filter by default

http://groups.google.com/group/cukes/browse_thread/thread/614aa04255b0fac1

suggested change is to remove:

config.action_controller.allow_forgery_protection    = false

from environment/cucumber.rb

This setting is aimed at making unit testing controllers easier, but we're usually doing full-stack testing with capybara or webrat & want the app to behave so-far-as-is-sensible as it does in production.

Not having forgery-protection enabled for the tests means if you use post to simulate e.g. a Paypal IPN notification coming in you won't receive a failure in cucumber, but you will receive a failure when you stage/deploy if you forgot to turn off forgery protection for that controller action.

webrat_steps "fill in the following" fails without selector

If you use the "fill in the following" step in webrat_steps.rb without specifying a selector, you get an error:
scope '//html' not found on page (Capybara::ElementNotFound)

This appears to be because it is effectively running the following:
within_selector 'html' do
within_selector 'html' do
# fill in the field
end
end

The second within_selector is failing.

@allow-rescue not working in rails 3

The relevant code looks like it tries to alias failsafe_response. This doesn't exist anymore in rails 3 and the cde has been moved into the ShowExceptions middleware. I tried to work out a olution but didn't get very far.

Running 'cucumber' in freshly generated Rails 3 beta3 app results in "Rspec is not missing constant Matchers!"

After creating a fresh rails3 beta 3 app with the following environment:

  • rspec-rails 2.0.0.beta7 or .beta8
  • cucumber 0.6.4
  • cucumber-rails 0.3.0
  • capybara 0.3.7
  • ruby 1.9.2 HEAD

Running cucumber right after generating the cucumber environment (no features defined) results in the following exception:

Using the default profile...
Rspec is not missing constant Matchers! (ArgumentError)
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:440:in `load_missing_constant'
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:153:in `block in const_missing'
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:151:in `each'
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:151:in `const_missing'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-rails-0.3.0/lib/cucumber/rails/rspec.rb:10:in `block (2 levels) in <top (required)>'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-rails-0.3.0/lib/cucumber/rails/rspec.rb:8:in `class_eval'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-rails-0.3.0/lib/cucumber/rails/rspec.rb:8:in `block in <top (required)>'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-rails-0.3.0/lib/cucumber/rails/rspec.rb:7:in `each'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-rails-0.3.0/lib/cucumber/rails/rspec.rb:7:in `<top (required)>'
/home/sr/.gem/ruby/1.9.1/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
/home/sr/.gem/ruby/1.9.1/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in `block in require'
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:197:in `load_dependency'
/home/sr/.gem/ruby/1.9.1/gems/activesupport-3.0.0.beta3/lib/active_support/dependencies.rb:209:in `require'
 /home/sr/src/my_app/features/support/env.rb:11:in `<top (required)>'
/home/sr/.gem/ruby/1.9.1/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
/home/sr/.gem/ruby/1.9.1/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/rb_support/rb_language.rb:124:in `load_code_file'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:85:in `load_code_file'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:77:in `block in load_code_files'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:76:in `each'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/step_mother.rb:76:in `load_code_files'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/cli/main.rb:48:in `execute!'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/lib/cucumber/cli/main.rb:20:in `execute'
/home/sr/.gem/ruby/1.9.1/gems/cucumber-0.6.4/bin/cucumber:8:in `<top (required)>'
/home/sr/.gem/ruby/1.9.1/bin/cucumber:19:in `load'
/home/sr/.gem/ruby/1.9.1/bin/cucumber:19:in `<main>'

Support for transactionless backends such as Mongo DB

Currently test operating on the model assume use of active_record, taking advantage of the built-in transactions. Some projects are shifting away to other persistence layers, such as document stores like Mongo DB, which has no transactions (to improve performance and scalability!).
To simulate transactions, we could take advantage of versioning, currently natively supported by fx Mongoid.

class Person
include Mongoid::Document
include Mongoid::Versioning
end

On running cucumber, each model class could be expanded to include this Versioning module (meta-programming) and then also add a previous_version method. Then somehow call previous_version on all documents affected after each test. Each test must then somehow ensure that an index is generated listing all documents with a counter for each saying how many times it was mutated. Then call previous_version that number of times for each. In effect this index would act as kind of a diff. Any other viable solutions?

MongoMapper also supports versioning: fx http://github.com/mrkurt/versioned

class Doc
  include MongoMapper::Document
  include Versioned
  key :title, String
end

script/generate cucumber should not magically rewrite my database.yml (erroneously)

Running script/generate cucumber rewrites my database.yml file, yet gives no indication that it has done this.

It rewrites any lines that end in "test:" This includes the "disable_connection_test:" lines I have in the config file for one project. This results in a segmentation fault in YAML (on my system), which was difficult to track down since I had no indication that the generate script would touch database.yml. The resulting error was difficult to trace since database.yml is frequently ignored in SCM; you can't rely on git to tell you it has been altered.

For me this behavior is far too magical and clever. The generate script should ask before it touches database.yml, or better yet print instruction so I can easily edit it myself. There are far too many edge cases for this to be done correctly. (Another project I ended up running the script several times, and found many duplicate lines had been added to database.yml)

Thank you for the fantastic tool.

features organized in subdirs are not fully supported

Under some circumstances Cucumber cannot find even the simplest step, e.g.
Undefined step: "I am on the new post page" (Cucumber::Undefined)

In order to reproduce, create a fresh rails 3 app: rails foo, populated it with Cucumber (as described in the README):

echo >> Gemfile <<EOF
group :test do
  gem 'capybara', :git => "git://github.com/jnicklas/capybara.git"
  gem 'database_cleaner', :git => "git://github.com/bmabey/database_cleaner.git"
  gem 'cucumber-rails', :git => "git://github.com/aslakhellesoy/cucumber-rails.git"
  gem 'cucumber', :git => "git://github.com/aslakhellesoy/cucumber.git"
  gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
end
EOF

bundle install
ruby script/rails generate cucumber:skeleton --rspec --capybara 
ruby script/rails generate cucumber:feature post title:string body:text published:boolean
ruby script/rails generate scaffold post title:string body:text published:boolean
rake db:migrate
rake cucumber

Then move the feature into a subdir:
mkdir features/foo
mv features/manage_posts.feature features/foo/

Run rake cucumber, it should pass. Now, make the feature fail, by introducing an error in the feature, e.g. edit the line When I fill in "Titlexyz" with "title 1". Now run rake cucumber again. This time it should correctly report cannot fill in, no text field. Run rake cucumber once again.

Cucumber even suggests me implementing steps like

Given /^I am on the new post page$/ do
  pending # express the regexp above with the code you wish you had
end

This behavior happens until I delete the rerun.txt, which contains the line

features/foo/manage_posts.feature:6

Reproduced with the lastest commit 50992e of cucumber-rails.

(::) BINARY FAILED TO LOAD STEP DEFINITIONS WHEN RUNNING FEATURE IN SUBDIRECTORY (::)

All of my features are in the admin subdirectory of features. When I run rake, everything passes but when I run the cucumber command, all of my steps are pending.

$ cucumber features/admin/sign_in.feature # steps are pending

If I move sign_in.feature into the parent features directory, the feature passes.

$ cucumber features/sign_in.feature # all steps pass

Running $ cucumber -r features features/admin/sign_in.feature works but shouldn't this happen by default?

I've edited my default profile in cucumber.yml to include the explicit require of the features directory but that just seems unnecessary.

Rails 3 with cucumber-rails 0.3.2 and cucumber 0.8.5 if it matters.

Update webrat config for rails-3

script/rails generate cucumber:install generates incorrect configuration for webrat

Here's what needs to happen for cucumber + rails 3 + webrat:

$ git diff
diff --git a/templates/install/support/webrat.rb b/templates/install/support/webrat.rb
index 0cf0521..7d53fd6 100644
--- a/templates/install/support/webrat.rb
+++ b/templates/install/support/webrat.rb
@@ -2,7 +2,9 @@ require 'webrat'
 require 'webrat/core/matchers'
 
 Webrat.configure do |config|
-  config.mode = :rails
+  config.mode = :rack
   config.open_error_files = false # Set to true if you want error pages to pop up in the browser
 end
 
+World(Rack::Test::Methods)
+World(Webrat::Methods)

capybara rack-test field should contain step support for textarea

I've submitted a pull request for this, it's a couple of loc change in the capybara step template.

http://github.com/nruth/cucumber-rails/commit/e5864f79bdcce637530e8a7d8495fc6d8827efab

The original posting was on Lighthouse. Apologies for the double posting - I somehow missed the issues link when looking for it first time round.

I am using the patch with rspec and rack-test. I don't know what will happen with selenium; the capybara API looks the same as for rack-test (it's a call on Capybara::Node methods), but as I haven't tested it with the other drivers I can't really say if it works or not there.

Dependency on database_cleaner

The config/cucumber.rb.erb template uses database_cleaner. However, the cucumber-rails gemspec does not express this dependency. Please add the dependency to the gemspec so that it may be caught by blunder/insert-tool-of-choice when the gem is installed.

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.