Rubymine - code folding ALL rspec examples - ruby-on-rails

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

Related

Ruby on Rails coverage tool that shows what is not being covered

I am developing an application using rails. Since the start we are using rspec to test our application. And we are using simplecov as a tool to show our test coverage.
But simplecov only shows the percentage of coverage inside a file, My question is if there is a tool that shows what line of code is not being covered?
If you click on the file name, simplecov will show you the line that is covered (with green) and not covered (with reds).
We use this in my workplace: https://codecov.io/#features
Codecov is used to help developers determine what lines of code were executed by their tests. There are three primary terms used to indicate the results of your tests: hit, partial and miss.
The value of 54% comes from a calculation of hit / ( hits + partial + miss) = coverage.
A hit is a line (aka statement) that is fully executed by your
tests.
A partial is a statement (typically a branch) that is not fully
executed.
Example if true:... will always be a partial hit because the branch was never skipped because true is always true.
A miss is a statement that was not executed by tests.
A grade of 54%, in simple terms, says "Half my code is tested". Use Codecov to investigate methods and statements in your code that are not tested to help guide you on where to write your next test and increase the coverage.

How can you call the cucumber 'step' method while using pry-byebug?

I've got a collision between the step 'pseudo function' provided by the byebug debugger (specifically, I'm using pry-byebug), and the step function provided by cucumber for running arbitrary cucumber steps.
I've tried to do my step function call with byebug's eval function, but this requires quotes to be nested three layers deep, and I haven't found a way to properly escape everything. For example, this doesn't work:
eval "step(\"I click on the \"Save order\" form button\")"
And no sooner have I typed up this question than I have found my own answer. So it goes!
You can work around the step pseudo function with Ruby's internal send method, which is available on everything that inherits from object. Within the pry-debug REPL:
self.send 'step', 'I click on the "Save order" form button'

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.

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

How to make Cucumber step definitions load according to feature file being executed

I would like to modify cucumber so that when a given feature is being executed (say "login.feature") I want only login_steps.rb to be loaded for the web steps. Other step files should not be loaded.
IMO this would be very useful to have the same steps but which differ in implementation work accordingly from the feature's name which is being executed.
Since I have almost a hundred scenarios and I would prefer if the steps were of high level steps this would make sense.
Any ideas?
Currently, the only way to accomplish this (short of patching cucumber itself) is to put each feature into a separate directory tree with its own env.rb file and step_definitions directory.
See this post on the mailing list for more details.
You may be able to achieve something like this using the Cellophane gem. It supports nested step definitions and you can turn off looking for shared steps. I'm not sure this will get you all the way to where you want to be, but I've found the developer to be very responsive if cellophane could be modified to get you what you're looking for.
Here is sample code for you,
.feature file
Scenario: Some description of the scenario
Given [some context]
When [some event]
Then [outcome]
.rb (Step Definition in ruby)
Given /^[some context]$/ do
// code module
// code module
end
This step definition will execute whenever [some context] comes in feature file.
says,
Given [some context]
When [some context]
Then [some context]
And [some context]
will perform in same operation. i.e Given, When, Then and And are generic.
Also, you can read behat document for better understanding - http://behat.readthedocs.org/

Resources