Say I have a feature line like this:
And I fill in "Category" with "soccer"
Even though this particular feature line is associated with a search form, I will need to use the same kind of step when dealing with forms in other features.
Where do you guys place this kind of "shared" steps, or in other words, steps that will be used in different features/scenarios?
I have created a file called shared_steps.rb with this content:
And /^I fill in "([^"]*)" with "([^"]*)"$/ do |field,value|
fill_in field, :with => value
end
I don't see anything wrong with placing this type of step in a 'shared_steps.rb' file, that seems perfectly fine.
I would, however, recommend trying to use steps with more explanatory language, such as 'And I search for "soccer" equipment'. There are well documented reasons that the built-in web_steps.rb file is no longer included with Cucumber.
Related
Does anyone know if it's possible to code fold all rspec examples either automatically on opening a spec file or preferably by key binding from within Rubymine.
For a spec with lots of examples it would be very handy to just collapse all examples to get an overview of the complete spec for a model, controller, etc. This would make it far easier to review and check for any missing edge conditions for example.
What I would like is for the it block to code fold so that they result in something like...
it 'should test something' do ... end
... without having to manually code fold every individual example.
Try going under Code > Folding > Expand All to Level > 3⌥⌘* in the menus. That should fold/expand to what you want.
Code folding menu in RubyMine
More here: https://www.jetbrains.com/help/ruby/2016.2/code-folding.html#folding_menu
I'm using:
Rails 3.2x
Spree 1.2
Ruby 1.9.3x
I'm trying to edit the title of one of my pages, and I cannot find where it is getting defined. It is showing up in my base ERB file as 'title', but that name is sufficiently generic to make it next to impossible to find where it is defined.
I have prodded everywhere I can think, I've tried searching for "title =", but nothing is working. I tried calling source_location on it, but that appears to only work on methods.
Any tricks for finding where a variable is defined?
I can't think of an elegant way. A dumb-but-probably-effective way would be to dump stack trace in your erb, then see what those locations are doing and if title is defined there. It has to enter somewhere between the start of program and invoking your erb.
When I can't find something, I use grep -ri some_string . at the command-line to recursively search all the content of the directory.
It's also a good tactic to let your editor search all the source code, since the ones worth using have the ability to search through all files in a directory.
it is created from a mixture of product names, a site config, and something else
An alternate trick is to add a HTML-comment section in your ERB file, and put the pertinent information for the components used to create the title into that section. Then, let the pages be generated and look inside the page's content to determine what table and row ID it is, the site_config filename, etc.
You really should be able to figure it out based on the parts that are concatenated to build the title and then search your database or files. That information isn't magically created out of thin air by Rails; Someone had to tell Rails how to define the title. But, people move on, or they don't document correctly, so try the embedded information trick.
I am implementing Behat with Mink, using the following feature:
Scenario: Search for another phrase that exists
Given I am on "/wiki/Main_Page"
When I fill in "search" with "Behavior Driven Development"
And I press "searchButton"
Then I should see "agile software development"
I have used the Goutte and Sahi, and the error is consistent. I get the error on "Then I should see "agile software development"
Scenario: Search for another phrase that exists # features/wikipedia.feature:13
Given I am on "/wiki/Main_Page" # WikipediaFeatureContext::visit()
When I fill in "search" with "Behavior Driven Development" # WikipediaFeatureContext::fillField()
And I press "searchButton" # WikipediaFeatureContext::pressButton()
Then I should see "agile software development"
Ambiguous match of "I should see "agile software development"":
to `/^I should see "([^"]*)"$/` from AccountFeatureContext::iShouldSee()
to `/^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/` from WikipediaFeatureContext::assertPageContainsText()
How to fix this issue.
Removed "I" from Then I should see "agile software development" step.
Your gherkin statement is matching more than one method's regex.
You likely have another method in your FeatureContext file which will match "I should see" causing the ambiguous error.
I found that when I came across this I had mistakenly spelled should with a capital S resulting in a new method being appended.
"I Should see "blah blah""
instead of
"I should see "blah blah""
Please check your feature files for any misspelled "I should see..." statements and check your feature context file and remove the extra method.
You'll then be able to write your statements in gherkin syntax properly including your I's
You are including 2 different contexts that define/implement the "same" Step Definition. The I should see "something" step definition comes for free in MinkContext, so my recommendation is removing it from your custom contexts: AccountFeatureContext and WikipediaFeatureContext and including MinkContext:
http://behat.org/en/latest/user_guide/context.html#multiple-contexts
If you put extra logic in your method definition, I recommend creating a new Sentence explaining what exactly you are pretending to see and there use subcontexts for reusing existing implementations:
http://docs.behat.org/en/v2.5/guides/4.context.html
Apart from this consider using another driver different to Sahi, it's no longer maintained:
https://packagist.org/packages/behat/mink-sahi-driver
This issue could also be avoided by making the regular expressions less ambiguous.
The approach you used above still lets you write ambiguous steps.
Best.
I'm using Tim Pope's rails.vim plugin and for the most part it highlights nearly everything I want, except Capybara's new DSL which contains keywords like feature, scenario, background etc.
I don't want to create a new syntax file just for those two keywords, just need to add them to the existing one.
Found rails.vim file which holds syntax stuff and added the keywords.
elseif buffer.type_name('spec') syn keyword rubyRailsTestMethod describe context it its specify shared_examples_for it_should_behave_like before after subject fixtures controller_name helper_name feature scenario background
This answer gave me the hint where to look: Automate rails.vim
I've been learning Ruby/Rails with vim. Tim Pope's rails.vim seems like a really good tool to traverse files with, but I keep getting these pesky "E345 can't find file in path" errors. I'm not vim expert yet, so the solution isn't obvious. Additionally, I've tried this and it doesn't apply to my problem.
As an example of the problem. I have a method format_name defined in app/helpers/application_helper.rb and it is used in app/helpers/messages_helper.rb. Within the latter file I put my cursor over the usage of format_name and then hit gf and I get that error. Similar disfunction with commands like ]f and [f
However, it works sometimes. I was able to gf from user to the app/models/user.rb
Ideas?
I think that is a limitation of rails.vim. It does not support “finding” bare methods. Supporting something like that would require one of the following:
an exhaustive search of all the source files for each “find” request
(which could be expensive with large projects),
“dumb” indexing of method names
(e.g. Exuberant Ctags and gControl-]; see :help g_CTRL-]), or
smart enough parsing of the code to make a good guess where the method might be defined
(which is hard to do properly).
If you know where the method is, you can extend many of the navigation commands with a method name:
:Rhelper application#format_name
But, you do not have to type all of that in. Assuming the cursor is on format_name you can probably just type:RhTabspaceappTab#Control-R Control-W (see :help c_CTRL-R_CTRL-W).