How to add capybara dsl syntax highlighting to vim syntax highlighting? - ruby-on-rails

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

Related

How to color specified text in vim?

Whenever I'm typing programming keywords in vim they get specific colors.
I'd like to create my own.
How can I color text with specified color?
I tried to find the answer but haven't found it yet
to extend C/CPP syntax (and that can apply to any language, just check for the already existing names, like Constant here) :
in your ~/.vimrc
if has("autocmd")
augroup filetypedetect
au BufNewFile,BufRead *.myext setf mysyntax
augroup END
endif
and in your ~/.vim/syntax/mysyntax.vim
runtime! syntax/cpp.vim
syn keyword myConstant foo bar foobar quack
hi def link myConstant Constant
to create new keywords from scratch :
syn match myKeyWord "foobar" contained
hi kwRed term=standout ctermfg=12 guifg=Red
hi def link myKeyWord kwRed
and you can call that with filetypedetect, or directly in your .vimrc
To extend a particular filetype syntax (like e.g. Java's), use :syntax and :highlight. If you just want to color particular words in a window, you can quickly use :match, or any of the available "multiple markers" plugins like mark.vim.
Look at match
:match Identifier /\w\+/
:2match Keyword /\v(if|else|then|break)/
See also :hi to see highlight groups. Alternatively, you could write a syntax file, which is /way/ more involved

Cucumber: Shared steps, where to place them?

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.

How can I syntax check (not render) a Rails 3 ERB template file?

I'm trying to have a git pre-commit hook perform a syntax check on all Ruby code; there is one on GitHub at https://github.com/cypher/git-ruby-syntax-check.
It attempts to check .erb files by erb -x to translate them into Ruby code and then passes the output to ruby -c for syntax checking. Unfortunately, Rails 3 introduced a custom ERB parser that is incompatible with Ruby's standard ERB, and so the pre-commit hook is finding errors where there are none.
Is there some equivalent to erb -x that will output Ruby code from a Rails 3 ERB file?
I have not dug much into either of these but you might try rails-erb-check (Git project) or this blog entry. I agree with shingara but the Blog Post describes a situation where this is useful and I wonder if you are in a similar position:
Diaspora is pretty fluid right now. This means we are have some green
tests, some missing tests, and other tests that check intent (not
implementation). In an ideal world, I suppose test cases would cover
all of our bases...
Until then, I've added a new task to my fork, check_syntax:all. This
breaks down further to the subtasks check_syntax:erb,
check_syntax:haml, check_syntax:haml_ruby, check_syntax:sass, and
check_syntax:yaml.
If you get an "argument list too long error" for rails-erb-check , you can try rails-erb-lint which scans your current views folder.

Cucumber & Vim: Getting around incorrect syntax highlighting for steps

One thing I've often noticed with cucumber is the syntax highlighting for steps such as:
Given /^I have a category with name "([^"]*)"$/ do |category|
...
end
Vim fails to escape the " inside the regex call, and consequently everything after the third " is highlighted as if part of a string. This make it difficult to pick up typos/incorrect methods and half my steps file ends up a (rather unhelpful) shade of red.
So...anyone know of any plugins which can correctly interpret those sorts of steps, and/or an elegant way to rewrite them that doesn't throw off syntax highlighting?
Cheers...
I think this issue is solved with current versions of vim-cucumber and related packages. I do not see what you are saying, using the latest versions of
vim-cucumber
vim-rails
Vim

In rails.vim why do I get "E345 can't find file in path" errors?

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).

Resources