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'
Related
I have a rails app with an interface like this:
<%= form_tag 'sound/speak', remote: true do %>
<input type='text' name='phrase'>
<%= submit_tag 'Say' %>
<% end %>
Which sends a request to a controller:
def speak
`espeak "#{params['phrase']}"`
end
It works but is this a bad idea in terms of safety? I'm just trying to make my server (raspberry pi) to speak whatever I write into the textbox. However in future this might be used by a group of friends. In this case I need to make sure it's impossible to, say, escape the quotes and the "say" command and execute a malicious script/command on the server. So, am I safe with this code?
What you're doing is dangerous. Consider things like this:
danger = 'antisocial tendencies" $(ls) "'
`echo "#{danger}"`
and think about what else you could do besides running ls.
You could use Shellwords (as in How to escape strings for terminal in Ruby?) but that would mean doing this:
Use Shellwords to escape params['phrase'].
Use string interpolation to build a command line.
Hand that command line to the backticks.
Execute a shell.
Let the shell parse the command line you just built.
Get the shell to run espeak with the desired argument.
You could avoid that by using the tools in Open3 or the multi-argument form of Kernel#system to jump directly to step (6) without involving a shell at all.
The shell is where the quoting problems come in so not involving a shell is a convenient way to cut out a whole class of errors and vulnerabilities. Avoiding the shell is also more efficient (although you'd be hard pressed to notice) and flexible as a bonus.
Thanks to sakurashinken for finding the sort-of-duplicate I linked to above, shame you deleted your answer.
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
Im trying to make a terminal but im stuck on one thing. In the doer program command do. I want docom to be the output of of the loadstring. input = io.read() its a lua terminal inside my program but nothing displays any output. Here is the code that is relevant:
docom = loadstring(input)
print(docom)
How do i make the output display? Because currently its like this:
welcome to the terminal!
loaded
do
do:
print("hello")
function: 0x809b60
do:
The third and fifth line are user inputs. how do i fix this so it shows the hello string instead of the function name. i want this to be able to manage it as i have everything else in the same lua script. please help.
You probably want print(docom()).
loadstring compile a script into a function. That's what you see function: 0x809b60.
loadstring does not run the function. Hence the call docom().
You may want to add error handling by checking whether docom is nil and by calling docom via pcall.
I am trying to work on whats wrong with my lithium current setup. I have installed the Xdebug and verified that remote host can establish the connection as requested.
http://myinstance.com/test/lithium/tests/cases/analysis/logger/adapter/CacheTest?filters[]=lithium\test\filter\Coverage
Please note in fresh installation in local environment , "Coverage" Filter is working as expected.
I added some test code inside the "apply" function in coverage.php but it is not even called !!!! Can some have experience in debugging the above URL ?
I am not able to understand why coverage filter is not called up and executed ...Any hints are highly appreciated !
The filters in the query string are added to the options in lithium\test\Controller::__invoke() and then passed into the test Report object created by the test Dispatcher. The Report object finds the test filter class and then runs the applyFilter() method for that test filter as can be seen in lines 140 to 143 of the current code. So those lines would be another place to debug. Those should wrap the run() method of your tests with this filter code inside the apply() method that uses xdebug_get_code_coverage() and related functions. You said you added test code in the apply method and it isn't called. I'm not sure what the issue is. Are you sure you are pointing to the right server and code location? It is possible to run tests from the command line. Maybe you should try that. See code comments in lithium\console\command\Test or run li3 test --help for info on how to use the command-line test runner.
I can confirm on nginx I also have /test/lithium/tests/cases/analysis/logger/adapter/CacheTest?filters[]=lithium\x5Ctest\x5Cfilter\x5CCoverage in my access log. The \x5C is expected url encoding of the backslash character.
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