Unable to understand zsh error while executing rake command - ruby-on-rails

When I execute %rake college:create[demo], I get the following error,
zsh: no matches found: college:create[demo]
Anybody has a solution for this?
when I execute rake -T, this is what I get when as one of the lines of the output:
rake college:create[config_name] # create a college profile
So, it is a valid command, but still zsh shows the error.

Try with:
rake college:create\[demo\]

You can also use noglob
noglob rake college:create[demo]
or just alias it in your .zshrc
alias rake='noglob rake'

zsh is trying to interpret your command as a wildcard file specication. college:create[demo] will expand to the list of existing files that match one of:
college:created
college:createe
college:createm
college:createo
This page shows some of the wildcarding that zsh performs, the specific example in this case being:
the [123] specifier, which indicates any of the characters 1, 2, or 3.
You need to escape the argument so that zsh doesn't think you're giving it a wildcard, such as with:
rake 'college:create[demo]'
The manpage for zshexpn shows all the expansions done on command lines in great detail. Search for Filename Generation for the xyzzy[demo] style generations.

If you are using rake via bundle exec or from bin/ dir add this to you .zshrc file:
alias bin/rake='noglob rake'
# or
alias rake="noglob bundled_rake

Related

xonsh "which" equivalent - how to test if a (subprocess mode) command is available?

I would like to test (from xonsh) if a command is available or not. If I try this from the xonsh command prompt:
which bash
Then it works:
user#server ~ $ which bash
/usr/bin/bash
But it does not work from xonsh script:
#!/usr/bin/env xonsh
$RAISE_SUBPROC_ERROR = True
try:
which bash
print("bash is available")
except:
print("bash is not available")
Because it results in this error:
NameError: name 'which' is not defined
I understand that which is a shell builtin. E.g. it is not an executable file. But it is available at the xnosh command prompt. Then why it is not available inside an xonsh script? The ultimate question is this: how can I test (from an xonsh script) if a (subprocess mode) command is available or not?
import shutil
print(shutil.which('bash'))
While nagylzs' answer led me to the right solution, I found it inadequate.
shutil.which defaults to os.environ['PATH']. On my machine, the default os.environ['PATH'] doesn't contain the active PATH recognized by xonsh.
~ $ os.environ['PATH']
'/usr/bin:/bin:/usr/sbin:/sbin'
I found I needed to pass $PATH to reliably resolve 'which' in the xonsh environment.
~ $ $PATH[:2]
['/opt/google-cloud-sdk/bin', '/Users/jaraco/.local/bin']
~ $ import shutil
~ $ shutil.which('brew', path=os.pathsep.join($PATH))
'/opt/homebrew/bin/brew'
The latest version of xonsh includes a built-in which command. Unfortunately, the version included will emit an error on stdout if the target isn't found, a behavior that is not great for non-interactive use.
As mentioned in another answer, which exists in the current version of xonsh (0.13.4 as of 15/12/2022) so your script would work. However, it outputs its own error message so it's necessary to redirect stderr to get rid of it.
Also, unless you redirect its stdout as well (using all>), it migh be a good idea to capture its output so the final version would look like this:
#!/usr/bin/env xonsh
$RAISE_SUBPROC_ERROR = True
try:
bash = $(which bash err> /dev/null)
print(f"bash is available: {bash}")
except:
print("bash is not available")

How to configure Atom linter-rubocop to run --rails flag always

I'm getting conflicting cops between my IDE and the console. How do I have Atom's linter-rubocop to always run with the --rails flag?
Error in Atom:
Error in console:
This is my config.cson:
...
"linter-rubocop":
command: "rubocop -R"
The settings-page for linter-rubocop describes that the command-option should be provided with an absolute path. That is, the output of which rubocop. Then you can add the parameter.

Cannot run rspec with filter tags

I have spec
RSpec.describe SearchFlight::Jet::SearchFlightRequest do
describe 'send search ticket request to Jetstar website', http_request: true do
context 'search ticket round trip successfully' do
# initialize
it 'return status 200' do
# my expects here ...
end
end
end
end
When I run rspec on my iterm, it couldn't run
bundle exec rspec -t ~http_request
zsh: no such user or named directory: http_request
Maybe it related to zsh command line (issue). I try to remove zsh from my iTerms 2 but it's not success. Any alternative shell for Rails dev ? Thanks
Try something like
rspec --tag "~http_request"
bundle exec rspec --tag ~http_request
I don't know why, but ~http_request has been recognized as the home folder of user "http_request".
You can escape ~ by using \~
bundle exec rspec -t \~http_request
Ref: https://askubuntu.com/questions/442394/why-does-cd-k-tab-expands-to-cd-kernoops-when-i-already-have-a-folder-name#
In zsh the ~name syntax is expanded to /folder/of/name/user. You can bypass this behavior by adding noglob at the beginning of the command: noglob rspec.... You can also alias the rspec command so that you don't have to put write that every time: alias rspec='noglob rspec '.

Rspecs Failed with Test::Unit automatic runner messages

versions
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-linux]
rails-3.2.18
rspec-2.14.1
parallel_tests-0.9.3
configs
.rspec
--color
--format documentation
--drb
--profile
.rspec_parallel
If installed as plugin: -I vendor/plugins/parallel_tests/lib
--color
--format documentation
--profile
when normal rspec success and not output Test unit messages
% RAILS_ENV=test bundle exec rspec
when parallel_tests rspec failed and output Test Unit messages
% RAILS_ENV=test bundle exec rake parallel:create\[4\] db:migrate parallel:prepare\[4\]
% RAILS_ENV=test bundle exec rake parallel:spec\[4\]
error
invalid option: -O
Test::Unit automatic runner.
Usage: /var/lib/jenkins/jobs/anyone.develop.spec/workspace/vendor/bundle/ruby/2.0.0/bin/rspec [options] [-- untouched arguments]
-r, --runner=RUNNER Use the given RUNNER.
(c[onsole], e[macs], x[ml])
--collector=COLLECTOR Use the given COLLECTOR.
(de[scendant], di[r], l[oad], o[bject]_space)
-n, --name=NAME Runs tests matching NAME.
(patterns may be used).
--ignore-name=NAME Ignores tests matching NAME.
(patterns may be used).
-t, --testcase=TESTCASE Runs tests in TestCases matching TESTCASE.
(patterns may be used).
--ignore-testcase=TESTCASE Ignores tests in TestCases matching TESTCASE.
(patterns may be used).
--location=LOCATION Runs tests that defined in LOCATION.
LOCATION is one of PATH:LINE, PATH or LINE
--attribute=EXPRESSION Runs tests that matches EXPRESSION.
EXPRESSION is evaluated as Ruby's expression.
Test attribute name can be used with no receiver in EXPRESSION.
EXPRESSION examples:
!slow
tag == 'important' and !slow
--[no-]priority-mode Runs some tests based on their priority.
--default-priority=PRIORITY Uses PRIORITY as default priority
(h[igh], i[mportant], l[ow], m[ust], ne[ver], no[rmal])
-I, --load-path=DIR[:DIR...] Appends directory list to $LOAD_PATH.
--color-scheme=SCHEME Use SCHEME as color scheme.
(d[efault])
--config=FILE Use YAML fomat FILE content as configuration file.
--order=ORDER Run tests in a test case in ORDER order.
(a[lphabetic], d[efined], r[andom])
--max-diff-target-string-size=SIZE
Shows diff if both expected result string size and actual result string size are less than or equal SIZE in bytes.
(1000)
-v, --verbose=[LEVEL] Set the output level (default is verbose).
(important-only, n[ormal], p[rogress], s[ilent], v[erbose])
--[no-]use-color=[auto] Uses color output
(default is auto)
--progress-row-max=MAX Uses MAX as max terminal width for progress mark
(default is auto)
--no-show-detail-immediately Shows not passed test details immediately.
(default is yes)
--output-file-descriptor=FD Outputs to file descriptor FD
-- Stop processing options so that the
remaining options will be passed to the
test.
-h, --help Display this help.
Deprecated options:
--console Console runner (use --runner).
Coverage report Rcov style generated for RSpec to /var/lib/jenkins/jobs/anyone.develop.spec/workspace/coverage/rcov
Rspecs Failed
try to
https://github.com/grosser/parallel_tests/issues/189
add spec_helper.rb
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
But, It did not resolve
delete spork
add
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner)
spec_helper.rb last line
resolved!
try this on your Gemfile
gem "test-unit", :require => false
or try test-unit 3.1.5.
https://github.com/test-unit/test-unit/issues/32#issuecomment-146885235
someone says about broke the application to run on Heroku. but likely the same as your problem

check syntax of ruby/jruby script using jruby -c syntax check (inside ruby code)

I am in a search of some way , using which in ruby code I should be able to create a temp file and then append some ruby code in that, then pass that temp file path to jruby -c to check for any syntax errors.
Currently I am trying the following approach:
script_file = File.new("#{Rails.root}/test.rb", "w+")
script_file.print(content)
script_file.close
command = "#{RUBY_PATH} -c #{Rails.root}/test.rb"
eval(command);
new_script_file.close
When I inspect command var, it is properly showing jruby -c {ruby file path}. But when I execute the above piece of code I am getting the following error:
Completed 500 Internal Server Error in 41ms
SyntaxError ((eval):1: dhunknown regexp options - dh):
Let me know if any one has any idea on this.
Thanks,
Dean
eval evaluates the string as Ruby code, not as a command line invocation:
Since your command is not valid Ruby syntax, you get this exception.
If you want to launch a command in Ruby, you can use %x{} or ``:
output1 = ls
output2 = %x{ls}
Both forms will return the output of the launched command as a String, if you want to process it. If you want this output to be directly displayed in the user terminal, you can use system():
system("ls")

Resources