How can I debug a single ruby script in netbeans? - ruby

All of this is on a windows xp box:
Netbeans managed to accept an existing rails project and allowed me to debug it just fine, but my project has a number of processing scripts that handle non-MVC aspects. The rails project is just a system for queuing requests for the execution of these scripts.
I've attempted to create netbeans projects using existing sources, but it fails for a number of reasons.
First, since I have a number of scripts in one place, netbeans complains that I can't add a source directory to the project because it already belongs to another project. If I put the script into its own, empty, directory and try to add that directory, netbeans stalls while trying to create the project and I have to end the process from the task manager.
If I create a new project for it, remove the default main.rb and replace it with the script I want to debug, the debug session will not start - netbeans complains that it cannnot find the program entry point.
It seems to me that if I can debug rails apps as easily as netbeans allows me to, that running a single standalone script would be trivial. What on earth am I missing?
UPDATE: Loading the script and doing "Debug/Debug File" isn't possible. The option is always greyed out, even for hello world.

Right click on the project, click Properties, choose Run, and change the Main Script to your script.
You can also debug a single file in Rails project by opening the file, then click Debug in menu toolbar, then Debug "file_name.rb". Or just press Ctrl-Shift-F5 on the opened file.

Related

Eclipse RCP App: How can I prompt the user to set the workspace

I want my RCP app to always prompt the user for the workspace location. I can specify a default location either with the -data arg in eclipse.ini or the osgi.instance.area.default property in configuration/config.ini. But I don't want the user to have to know about and edit either of these files to change the workspace location.
Setting the preference Prompt for workspace on startup has no effect. I launch the app in a clean workspace, with no -data arg or osgi.instance.area.default property set, and it creates a workspace folder in the current directory, and does not prompt to select a location.
I use a copy of the IDEApplication class for my application. I see that in line 188 which is one of the first lines run after start(), the platform location is already set, and this prevents the dialog from showing. I don't know why it's already set before even trying to launch the UI, and setting the preference has no effect. (I verified in configuration/.settings/org.eclipse.ui.ide.prefs that SHOW_WORKSPACE_SELECTION_DIALOG=true).
I tried re-setting the location by adding
instanceLoc = instanceLoc.createLocation(instanceLoc, null, false);
at the beginning of checkInstanceLocation(). This enables the workspace chooser dialog to come up, but setting the location this way has no effect on what the app actually uses for its instance area when it launches.
I thought that maybe some earlyStartup code in my app may be interfering, as I read that if you access the preferences too soon you can prevent the workspace chooser from opening. So I commented out the few earlyStartup declarations I had, and still I can't get the workspace chooser dialog to show.
The problem turned out to be that some classes loaded as dependencies of my OSGI service were accessing the class ResourcesPlugin, which causes the workspace location to be set immediately. Since this was happening before the workspace chooser dialog was launched, the location used was the value of the -data arg if specified, otherwise $(pwd)/workspace.
I tried resolving the issue by adjusting the start level of my service plug-in. With a start level of 7 or higher, the workspace chooser dialog was no longer pre-empted. However, the service did not work properly then. After numerous unsuccessful attempts to make the service work properly with a custom start level, I abandoned that approach and re-worked my code so the reference to ResourcesPlugin occurs later in the application startup process. Specifically, I moved it to the postWindowOpen method of my custom WorkbenchWindowAdvisor implementation.

Run a powershell script or batch file on target server after publish

I'm using visualstudio.com and Hosted build controller to build and publish my website to a server with web deploy.
After the publish I want to execute a file (powershell script or batch file).
I know that I could create a Windows Service that runs on target server and uses the FileSystemWatcher to monitor changes and run a file when it detects a file change.
But is there any better way to do this?
I assume you've customized your XAML workflow to add a new Activity (of type InvokeProcess maybe?) to handle the Publish part.
If so, you can add another Activity that will execute your custom powershell (say custom.ps1) script like so:
Add custom.ps1 to your source control
Add the folder of custom.ps1 to those used when building (Right click your build definition > Edit Build Definition... > Source Settings tab > add your folder here)
Add a new InvokeProcess Activity after the publish, that will call powershell.exe and give "custom.ps1" as the argument.
The basic idea is: deploy the .ps1 along-side your source code, and execute it after publishing is over.
Also, I strongly encourage you to take a look at Ewald Hofman's great series, especially the following:
http://www.ewaldhofman.nl/post/2010/11/09/part-14-execute-a-powershell-script.aspx

Configure launch command in Code::Blocks

I recently discovered Emscripten, and after downloading it, I decided to see if I could get it to work with Code::Blocks, so that I could easily test my applications to see how they performed when running as JavaScript.
I created a new compiler configuration, and set up all of the toolchain executables, except for the resource compiler (which doesn't seem to give me any problems), and the debugger. I wasn't really sure what to put in the debugger, because I remembered the debugger field as being a text-box. But when I looked, all that was there was a drop-down menu.
I managed to find a "Debugger" menu in the "Settings" menu, and when I opened it, there was a button called "Create config".
I created a new configuration, and pointed the executable path to "node.exe" (which runs .js files). I then went back to the compiler settings, and chose my new debugger in the drop-down.
I then tried to build and run a simple hello world application. But once it finished building, it gave me the message Execution of '[my file] ' in '[my project folder] 'failed. The actual build seemed to be successful, so I decided to manually run node.exe from the command line to see if I had configured the debugger incorrectly. And as I expected, it ran successfully.
While I was glad that I had successfully configured the compiler, I still was confused as to why the app didn't want to run. I also set Emscripten to create HTML files instead, to see if Code::Blocks would somehow recognize the appropriate program, and open it in the web browser instead. Of course that didn't work either.
What I am trying to figure out, is how I configure Code::Blocks' run command. Perhaps the debugger isn't even the right place to be looking. But I really need someone to help me figure out how I can configure this in Code::Blocks, as this is currently the only thing that is really giving me any trouble.
Thanks.
Possible but less ideal solution:
After some time, I was able to come up with a solution. However, I am sure that there are better alternatives.
To use this method:
Create a new build target called RunScript.
Set the compiler to No Compiler.
In the project properties, set the type to Console application.
Uncheck Auto-generate filename extension, and set the output filename to RunButton.bat.
Create a new file called RunButton.bat (or whatever you entered as the output filename).
Whatever you put in RunButton.bat will now be executed when you click the run button.
I also created a new virtual target that contained my RunScript target, and my main target, so that I don't have to switch targets whenever I want to test my application.
Problems with this method:
While this method does work, it is not ideal, as it requires you to have two extra targets (including the virtual target that I made for convenience). I would rather be able to just have everything contained in one target.
Slightly better solution:
A new solution that I decided to use, is to simply use the configure tools menu to create a tool that points to a batch file that runs my compiled programs.
To use this method:
Go to Tools>Configure Tools...>Add.
Fill in the name, and point the executable to the script that you want to run when this tool is used.
Fill in any needed parameters. You can use the built in ${TARGET_OUTPUT_FILE} macro to pass your output application as a parameter.
You can now use your tool by going to Tools>{My tool}, but you can set a hotkey by going to Settings>Editor...>Keyboard shortcuts.
Click the plus button by Tools, and click on your tool to set a shortcut for you tool.
Problems with this method:
While this method does eliminate the extra build targets, it doesn't let you run your script or run non-executable files by clicking the run button; which was the original intent. On top of this, you have to create a new tool anytime you want to add a new script.
I am hoping that someone else will be able to show me a better way of doing this, but for now this will work.
Might be a little late, but I was able to get the codeblocks run button to run any command by using a few post-build steps. The reason I need this is because my laptop has nvidia "optimus" and in order for my output program to see the discreet graphics card, I have to run it with the optirun prefix. So I added the following to the post-build steps in build options:
mv $(TARGET_OUTPUT_FILE) $(TARGET_OUTPUT_FILE)_bin
echo #!/bin/sh > $(TARGET_OUTPUT_FILE)
echo optirun $(TARGET_OUTPUT_FILE)_bin >> $(TARGET_OUTPUT_FILE)
chmod +x $(TARGET_OUTPUT_FILE)
It basically renames the output binary and creates a script replacing the original output binary name. When pressing the run button, the script is executed instead of the output.
On windows, you might have an issue running an exe extensioned file as a batch script so what if you generate the output file with a bat extension like in your first method, but with compilation and then rename it to exe in the post-build like this:
move $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).bat $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).exe
echo [WHATEVER YOU NEED TO RUN] > $(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).bat

Is it possible to run terminal/command prompt inside Rubymine?

I would work much faster if I could have some kind of command line running inside rubymine, is this possible? When testing I repeatedly have to switch to my terminal window and it gets quite annoying.
I can run rails console and also the sandboxed version side rubymine aswell as my rails server and spork server.
It would be nice to have a command prompt inside rubymine also would speed things up. Infact that would make rubymine 100% perfect for my rails development as it does everything else require.
There is no such feature in IDEA platform based products. You need to run terminal externally. Note that you can create an External Tool to run terminal window in the current file or module directory for convenience.
UPDATE: Terminal (SSH console) was added in PhpStorm/WebStorm 7.0, IDEA 13, RubyMine 6, PyCharm 2.7.3.
I have used CrazyCoder's instructions to do this. Here are the instructions for Windows:
File, Settings
bottom half of menu is titled IDE Settings, look in this list to find External Tools
Click in the only available button (for most), [+]
give your custom thing a name ("terminal"? "command prompt"?)
most of this stuff you just leave blank
click the [...] button next to Program, then simply navigate to Windows/system32/cmd.exe
Lastly, unless you want to have your starting command line (terminal) path as C:\Windows\system32 (CHANGE YOUR PATH), simply click on the [...] next to the "Working Directory" just below, and change your path to Desktop or whatever it is you prefer.
Click OK.
You're done! It's that easy. Now to access this (no restart required), click on Tools, and then under 'XML actions' (for me anyway) you should find your "terminal" or "cmd" or whatever it is you called it. You can test it out with an 'ipconfig' command. You can always go back to the the settings/external-tools place you went to in the first place to edit your settings (like your default path), or to make another custom tool, because this (RubyMine External Tools creator) is obviously a very powerful tool.
If someone is searching this for rubymine in version 7.
Press Alt+f12 for the terminal.
Source : https://www.jetbrains.com/ruby/webhelp/working-with-embedded-local-terminal.html

Ways to support manually executed tests? (that can be used on a Mac)

Are there any tools that can be used on a Mac to support manually executed tests? I have a number of tests that I'm executing manually and which I'm currently documenting using merely a plain text file. "Tools" can be interpreted rather loosely here, anything that's a step up from the plain text file would be useful: a template for some suitable application, supporting AppleScript scripts, a web-based system, a full-blown application ...
Some things that would be great to have better support for (see also the example below):
Checking off each step while you're manually executing the test.
Showing the next step(s) in a small window that is always kept in front of all other windows.
Automatically updating the 'last tested' and 'using svn revision' info.
Keeping a record of all previous testing rounds (not just the last one).
...
Any suggestions for any such "tools" that can be used on a Mac?
An example (faked) entry from the plain text file to give you a better idea of what I'm looking for:
- Check that exported web pages render properly in Safari.
Last tested: 2010-03-24
Using SVN revision: 1000
Steps:
- Open a new document.
- Add some items to the document.
- Export the document to a web page "Test.html" in a new folder "Export Test"
on the Desktop.
- Open the web page in Safari, script:
tell application "Finder"
open file "Test.html" of folder "Export Test" of desktop
end tell
Expected results:
- The web page should appear properly with all items shown.
Clean up steps:
- Remove the folder "Export Test" from the Desktop.
( Note: for those unaware, the snippet of AppleScript in the above can be executed from most text editing applications through the Services menu by selecting the snippet and using: the application menu > Services > Script Editor > Run as AppleScript. This is quite useful to automate some steps for tests that are difficult to automate as a whole. )
Have a look at TestLink - it's a PHP app that you should be able get get working on a Mac easily enough, and will do most of the things you're looking for.
You might want to look into our test management tool TestRail, as it does most of what you mentioned. TestRail is a PHP application (web-based) and can be installed on almost any system.

Resources