1
votes

I'm starting to make BDD with cucumber.

I have written my first scenario like this

Scenario: ...
Given I am on the new event page
And I fill in "title" with "tata"

With these steps

Given /^I am on (.+)$/ do |page_name|
  visit("/event/new")
end

When /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |field, value|
  fill_in(field.gsub(' ', '_'), :with => value)
end

It works good, nice. Now, I want to use the send function to visit a page. So I have changed the first step like this.

Given /^I am on (.+)$/ do |page_name|
  self.send("new_event_path".to_sym)
end

The page is found but the fill_in does not work because an element is not found.

 Unable to find field "title" (Capybara::ElementNotFound)

I don't understand why it's not working with the send function?

1
Your second implementation of "I am on" doesn't visit anything, it just evaluates the URI and throws it away.Dave Schweisguth
Add do you know a solution to be more generic than the first solution ? I have see this solution here : github.com/cucumber/cucumber-rails-training-wheels/blob/master/…elhostis
ok, I just have to do a visit(path_to(my_page))elhostis

1 Answers

0
votes

The solution :

Given /^I am on (.+)$/ do |page_name|
   visit(self.send("new_event_path".to_sym))
end

Thanks Dave, your response help me :)

Eric