db:migrate fails in Emacs shell - ruby-on-rails

When I rake my db in emacs, it fails– although it works fine in terminal. The error is related specifically to an environment variable that emacs doesn't seem to be picking up on. What is the best way to resolve this in .emacs? Do I need to source my profile every time I start emacs?

Which emacs shell are you using? There are a few different types which are good for different cases. I recently read this article which you may find informative: http://www.masteringemacs.org/articles/2010/11/01/running-shells-in-emacs-overview/
I suggest trying simply M-x shell which will simply run your default shell in emacs (usually bash).

Related

kitchen-docker: How to run a shell command before kitchen converge

When using vagrant machines with test-kitchen the pre_create_command allows you to specify a command which is run locally before the vagrant machine is being created. With kitchen-docker no such configuration option seems to exist, and bending chef_omnibus_url as suggested here isn't an option.
The script specified as pre_create_command for the testing vagrants generates a local chef data bag.
Is there a solution around which I've overlooked?
Best practices include Rakefile and Thor.
In essence you control your tests from a Rakefile. For example:
rake style
This will run all commands under your style task (maybe lint/syntax/unit and kitchen tests). Of course you can modify your tasks to perform whatever you like. Here are some good resources:
https://blog.chef.io/2015/04/21/overview-of-test-driven-infrastructure-with-chef/
See the Supporting Tools and Dependencies section.
Here is an example Rakefile:
https://github.com/chef-cookbooks/chef-server/blob/master/Rakefile
I sketched a patch for kitchen-docker here. However, as the discussion on this pull request shows, there are arguments against an appropriate functionality in kitchen-docker, namely the one that such functionality (if ever) should go in the kitchen core.
So for the time being we have to live with this inconsistency between docker and vagrant, and this is where thun's answer comes into play.
This can be done using
driver_config:
provision_command: <command>
in kitchen.yml
Check more here
Kr,
Rshad

How to get color in Windows gitbash using bundle exec rake test

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.

Resolving Address Space is already occupied error using Cygwin and Ruby

I keep getting the same type of error messages and I have really done all I can to get rid of them. The message is as follows, only the module can vary at times:
ruby 5740 child_info_fork::abort: address space needed by 'date_core.so' (0x600000) is already occupied
These messages occur at various times when trying to run Rails, such as “rails console”.
I am running the following environment:
Windows 7 Ultimate 64-bit
Cygwin Net using setup 2.774 (installed from Internet mirrors)
Ruby 1.9.3p392
Rails 3.2.11
I have taken the following steps attempting to fix this:
Deleted all BLODA and restarted, including Norton 360 and Malwarebytes. (BLODA is Big List of Dodgy Apps.)
Deleted and reinstalled Cygwin.
Executed “rvm implode” and rebuilt the RVM and Ruby on Rails environment.
Used CMD & ASH to run “peflagsall” & “rebaseall”. Ran “rubyrebase”. Restarted.
Used FIND to build a file of all *.so & *.dll files. Ran “rebase -T”. Restarted. This has also been done using the “-b 0x77000000” switch.
Used same file to create “to_peflags” script issuing peflags against each individual file. Restarted.
All repair attempts have been futile. At times, “rebase -si |grep ‘*’” would be clean. Any attempt to run “rails console” or similar commands results in Address Space Occupied messages. Subsequent “rebase -si” would then again show conflicts.
I have been trying to run “peflags” against the Ruby modules, but I only get “skipped because could not open” error messages there. File permissions and ACL both show correct permissions. The same error occurs whether or not Administrator is used.
This is pretty frustrating. I would like to fix my current environment, but I am considering moving to MSYS or SFU, but I don’t know if either of those are decent options. I am also considering going native UNIX, but I’ll leap off the cliff when I get to it.
For now, does anyone have a fix for this specific error for me? Thanks…
I have used procexp to monitor "rails console" execution. Bash is calling cmd.exe to run the rails.bat file. Cmd.exe runs in ASLR mode. Used Microsoft EMET 3.0 to turn off mandatory ASLR and bottom up ASLR for both bash and cmd. Cmd.exe still runs in ASLR mode. It must be compiled that way.
Updated registry to set HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\MoveImages to 0, -1 then 1. 0 caused system problems. -1 had no effect. 1, which was supposed to be the default, helped somewhat as long as EMET changes were in place. But, it was unreliable as Address Space Occupied would eventually recur.
Decided to attempt to install a command processor that either didn’t require ASLR or allowed me to disable it using PE flags. I installed TCC/LE and attempted to get Cygwin Bash to use it to process .bat files. I tried using the path variable, the COMSPEC variable and changes to batfile and cmdfile in the registry all to no effect. Cygwin Bash must either have it hard coded or some nonobvious control.
My fix is to replace my environment. I know I will eventually migrate to some Unix, but for now I am converting to MinGW/MSYS and RubyStack. All I want to do is to get a stable RoR (Ruby on Rails) environment running for today. I don’t see that happening using Cygwin with Windows 7 Ultimate. I keep running into too many problems and this one is a very, very tough nut to crack. Thanks…

Ruby - ExecJS not loading (I have the proper materials and PATH location.) [Windows]

I am having a problem with the ExecJS in that it is unable to locate a required Runtime. I am using Windows, and I have both Windows CScript and Node.js installed on my computer, but neither of these guys are being invoked.
As a result, I am unable to run any rails task that involves this (I cannot even load my rake list in RubyMine to call actions such as db:create to create my databases from a fresh project.)
I am capable of accessing both csript and node from the command line, and I have checked my environment variables and their proper file locations are in the PATH. There's something else ruining my ability to use ExecJS. Has anyone else had a similar experience where you have had all of the right stuff, but something is still going wrong?
When Ruby spawns child process to invoke CScript or Node, it will use the same rules that allow cmd.exe execute them from the command line.
But, sometimes, stuff in your registry or your environment variables can affect this process.
At RubyInstaller project we collected a series of troubleshooting items that could possible be the culprit.
Please check that COMSPEC environment variable is set to use cmd.exe and nothing like TCC/LE or other stuff.
C:\>SET COMSPEC
Also, check that your registry do not contain an AutoRun key, which will also affect Ruby.
C:\>REG QUERY "HKCU\Software\Microsoft\Command Processor"
C:\>REG QUERY "HKLM\Software\Microsoft\Command Processor"
If you see a key AutoRun in one of the above commands, that means something is setup to automatically execute everytime a new cmd.exe is started, which is bad for some cases.
Please follow the instructions in the Troubleshooting page on how to remove it.
This also affects gem installation that requires compilation, but if is not failing for you then the problem might be something else.
Hope that helps.
I was having similar problems, my basic skeleton app wouldn't run despite having Node.js installed, and then trying therubyracer gem. Finally I decided to use my troubleshooting mantra with windows, "When in doubt, run as admin". So I ran my rails cmd as an admin and it worked fine after that.

Using Rails commands with a disabled command line

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.

Resources