I'm interested in using Phantomjs and I'd like to run it from my Ruby on Rails application. However, this is a command line tool (i.e. I'd need to run something like phantomjs rasterize.js http://raphaeljs.com/polar-clock.html clock.png in my terminal). How would I execute a command line tool from my app?
Use backticks in your ruby code e.g.:
output = `phantomjs rasterize.js http://raphaeljs.com/polar-clock.html clock.png`
Related
I would like to know when we run commands like rails new, rails generate. Which files are actually executed. In general for other tools like rake, rspec( not sure they are called command line tools ) or any other such gem, which files are executed first( at the beginning ).
Thanks.
Most of them are located in this folder https://github.com/rails/rails/tree/3be590edbedab8ddcacdf72790d50c3cf9354434/railties/lib/rails/commands
For instance this https://github.com/rails/rails/blob/3be590edbedab8ddcacdf72790d50c3cf9354434/railties/lib/rails/commands/application/application_command.rb calls the app generator https://github.com/rails/rails/blob/3be590edbedab8ddcacdf72790d50c3cf9354434/railties/lib/rails/generators/rails/app/app_generator.rb
I am following Rails Tutorial. I am on section 3.7.1 and I am trying to get color in my gitbash command prompt when running bundle exec rake test. I have tried installing ansi, the win32console gem and the gem called turn and nothing seems to work.
Is it even possible to get red and green colors when running bundle exec rake test?
You definitely can get colored output to show up. But not with using the standard Windows cmd.exe or powershell. Gems won't help. You need to need add the ability to correctly interpret ANSI escape codes to your system -- something that cmd and powershell aren't able to do. (ANSI.sys was how ANSI escape codes were handled under DOS. cmd and powershell don't use it.)
You need to (1) install ANSICON and/or (2) install and use a different console/console emulator or shell that handles colors (ANSI escape codes).
(1) ANSICON is a program for Windows that interprets ANSI escape codes so that color is displayed. It kind of runs 'on top of' cmd or powershell. You can set it up so that it's always used whenever you use cmd or powershell, or use it only at specific times. Most people install this and are really happy with it.
Jason Karns wrote a blog post about installing and using ANSICON for git bash (on Windows) that folks have found helpful.
(2) Here are the popular options for alternatives to cmd/powershell. These are console emulators and tools and shell alternatives:
ConEmu - ("ConEmu-Maximus5") This is a console emulator, not a shell. You can use it with any shell (cmd, powershell, cygwin, bash, etc). But in day-to-day use, once you set it up, you use it just like you'd use cmd.exe or powershell, etc. (I use this so know more about it than the other choices. I have configurations for it to start up with different git/ruby version/rails version configurations as needed. I don't use ANSICON because I use ConEmu whenever I need to open up a console.)
Console 2 - Like ConEmu, this is a console emulator that adds functionality above and beyond cmd.exe (including displaying ANSI colors). You can use it with existing shells (e.g. powershell, etc.) Here's a SO answer that talks about using Console 2.
Console Z - a fork of Console 2 that is current and actively maintained. I haven't ever used it, but here is some info on how you'd configure Console Z to work with git bash.
You can also (or instead of) use a Unix-like shell (or suites):
Cygwin is the best known suite of Unix-like commands that runs in Windows. Comes with shells (e.g. MinTTY) that can be used and will work with ANSI codes
Babun A windows shell that sits on top of a cygwin install. Configurable; you can create configurations (e.g. for git bash or rvm or whatever) and share them as plug-ins. (Uses the mitty console.)
MinGW - A "Minimalist GNU for Windows" that has a GNU toolset for windows, focused on those tools needed for development. (IOW, it's a smaller and slightly different set than Cygwin provides.) DevKit, used to complie ruby gems into native windows code, uses MinGW.
MinSYS - "[A] contraction of "Minimal SYStem", is a Bourne Shell command line interpreter system. Offered as an alternative to Microsoft's cmd.exe, this provides a general purpose command line environment, which is particularly suited to use with MinGW, for porting of many Open Source applications to the MS-Windows platform; a light-weight fork of Cygwin-1.3, it includes a small selection of Unix tools, chosen to facilitate that objective." (From the MinGW site:)
Some searching might turn up additional options. These are the options most talked about and used (based on talking with others IRL, StackOverflow, and doing searching now and previously.)
Install and set one of those options (it won't take long), and then you'll be all set to see the helpful colors used by RSpec or git or whatever.
I have recently started using ruby to write tests for selenium but I would like a way for the tests to be exported into a results file.
For an example of what i mean. I was exporting the tests from the IDE to html and then running them using
java -jar selenium-server-standalone-2.39.0.jar -htmlSuite *firefox http://google.com /path/to/suite.html /path/to/results.html
in the command line and it would run the suite.html and then post the results in results.html
Is this possible in Ruby?
Looks like someone has already taken on the same challenge before. See this article how to export results when running selenium ruby webdriver scripts to output files from command prompt ruby window.
You may have to write up a rake file, but I believe it will be a good experience that will make you better acquainted with ruby and how to go about selenium testing with it.
I have a script in my lib/config/my_script.rb which make a synchronization from MAIN database to my Database.
How i can run it from command line? And it will be working?
ruby my_script.rb
I also wanted to provide a Ruby quick reference guide that will give you additional information on command line arguments for the ruby command as well as a wealth of other information on Ruby.
Ruby Quick Reference Guide: http://www.zenspider.com/Languages/Ruby/QuickRef.html
ruby lib/config/my_script.rb
or
./lib/config/my_script.rb
I'm using a public Windows computer where the command line has been disabled. By using Instant Rails I'm able to create customize and test rails apps to some degree but can't use the Rails commands.
Question:
How do I use these commands with a disabled command line?
I've tried using SciTe, Notepad++ but all these just access the same disabled cmd so those won't work.
Some editors that deal with Rails specifically can do this. Netbeans, RadRails and RubyMine come to mind.
However, if your command line is disabled, you're probably not going to be able to `install them either.
As EmFi said, NetBeans has both a built-in Rails console and the ability to run migrations and Rake tasks from a menu. So with NetBeans, you'd be able to run migration and Rake tasks without needing a command line at all.
Here's another option...
If you're able to install software on the machine, maybe you could install something like Cygwin or MinGW. They provide a command prompt with a Unix-like environment. I've used both. Personally, I think MinGW would give you a smoother, simpler experience with fewer gotchas, but Cygwin is very popular.