<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>No Pugs : Category netbeans, everything about netbeans</title>
    <link>/category/netbeans.rss</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>they're evil</description>
    <item>
      <title>how to debug a Ruby on Rails script in NetBeans</title>
      <description>&lt;p&gt;So you&amp;#8217;ve written some helper script or possibly a script that&amp;#8217;s ran by cron to do some background work on your site (updating full text indexes, sending out notification emails, generating reports, etc) but you can&amp;#8217;t find a way to debug it in rails so that it hits your breakpoints.  Annoying.&lt;/p&gt;

&lt;p&gt;What I did to solve this was first to create a rake task that creates other rake tasks based on script name.  This way you can debug it the way you would debug any rake task (and it&amp;#8217;s also convenient to be able to execute scripts from the rake context menu anyways.)  This allows you to run any script by right clicking on the project in Netbeans, and going to &amp;#8220;Run/Debug Rake Task-&gt;script-&gt;your_killer_script.rb&amp;#8221;&lt;/p&gt;

&lt;p&gt;Place this in a file called scripts.rake and place it in your lib/tasks folder&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;find&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;

namespace &lt;span class="sy"&gt;:scripts&lt;/span&gt; &lt;span class="r"&gt;do&lt;/span&gt;
  &lt;span class="co"&gt;Find&lt;/span&gt;.find(&lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="il"&gt;&lt;span class="idl"&gt;#{&lt;/span&gt;&lt;span class="co"&gt;RAILS_ROOT&lt;/span&gt;&lt;span class="idl"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class="k"&gt;/script/&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) &lt;span class="r"&gt;do&lt;/span&gt; |p|
    &lt;span class="r"&gt;if&lt;/span&gt; &lt;span class="co"&gt;File&lt;/span&gt;.file?(p) &amp;amp;&amp;amp; p !~ &lt;span class="rx"&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;span class="k"&gt;(&lt;/span&gt;&lt;span class="ch"&gt;\.&lt;/span&gt;&lt;span class="k"&gt;svn-base|&lt;/span&gt;&lt;span class="ch"&gt;\.&lt;/span&gt;&lt;span class="k"&gt;netbeans-base)$&lt;/span&gt;&lt;span class="dl"&gt;/&lt;/span&gt;&lt;/span&gt;
      desc &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;Run &lt;/span&gt;&lt;span class="il"&gt;&lt;span class="idl"&gt;#{&lt;/span&gt;&lt;span class="co"&gt;File&lt;/span&gt;.basename(p)&lt;span class="idl"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
      task &lt;span class="co"&gt;File&lt;/span&gt;.basename(p, &lt;span class="s"&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="dl"&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;) =&amp;gt; &lt;span class="sy"&gt;:environment&lt;/span&gt; &lt;span class="r"&gt;do&lt;/span&gt;
        load p
      &lt;span class="r"&gt;end&lt;/span&gt;
    &lt;span class="r"&gt;end&lt;/span&gt;
  &lt;span class="r"&gt;end&lt;/span&gt;
&lt;span class="r"&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Then, right click on your project and hit &amp;#8220;Run Rake Task-&gt;Refresh List&amp;#8221;&lt;/p&gt;

&lt;p&gt;You should now be able to right click on your project and hit &amp;#8220;Debug Task Rake Task-&gt;script-&gt;your_killer_script.rb&amp;#8221;&lt;/p&gt;

&lt;p&gt;It should hit any breakpoints you have set.  Happy debugging!&lt;/p&gt;

&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-5048333526809695";
/* 468x60, created 12/12/08 */
google_ad_slot = "9778167023";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;

&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;</description>
      <pubDate>Fri, 12 Dec 2008 02:12:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:f40584ae-dc91-41b7-9d0a-85dc51660829</guid>
      <author>azimux@gmail.com (miles)</author>
      <comments>http://nopugs.com/2008/12/12/how-to-debug-a-ruby-on-rails-script-in-netbeans#comments</comments>
      <category>Ruby on Rails</category>
      <category>Netbeans</category>
      <trackback:ping>http://nopugs.com/trackbacks?article_id=15</trackback:ping>
      <link>http://nopugs.com/2008/12/12/how-to-debug-a-ruby-on-rails-script-in-netbeans</link>
    </item>
    <item>
      <title>How to debug an individual rails test in Netbeans</title>
      <description>&lt;p&gt;In Netbeans, to test a Ruby application normally I right click on the project and go to &amp;#8220;Run Rake Task -&gt; test&amp;#8221;&lt;/p&gt;

&lt;p&gt;A problem arises when I try to debug a test.  None of the breakpoints get hit.   I think this is because a new process is spawned off to actually run the tests and the debugger is attached to the parent process.  So you can really only hit breakpoints involved in spawning the tests but none in the tests or in any of your application code called by the tests.&lt;/p&gt;

&lt;p&gt;Opening an individual test and right clicking in the buffer and hitting &amp;#8220;Debug your_mom_test.rb&amp;#8221; seems to fail for me with rails 2.1.  I was able to correct this by changing the line at the top of the test from&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;require &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;test_helper&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;div class="CodeRay"&gt;&lt;pre&gt;&lt;span class="CodeRay"&gt;&lt;span class="gv"&gt;$:&lt;/span&gt;.unshift &lt;span class="co"&gt;File&lt;/span&gt;.join(&lt;span class="co"&gt;File&lt;/span&gt;.dirname(&lt;span class="pc"&gt;__FILE__&lt;/span&gt;), &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;..&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;, &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;lib&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;) &lt;span class="r"&gt;if&lt;/span&gt; &lt;span class="gv"&gt;$0&lt;/span&gt; == &lt;span class="pc"&gt;__FILE__&lt;/span&gt;
require &lt;span class="co"&gt;File&lt;/span&gt;.dirname(&lt;span class="pc"&gt;__FILE__&lt;/span&gt;) + &lt;span class="s"&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="k"&gt;/../test_helper&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Enjoy hitting your breakpoints while testing!&lt;/p&gt;

&lt;script type="text/javascript"&gt;&lt;!--
google_ad_client = "pub-5048333526809695";
/* 468x60, created 12/12/08 */
google_ad_slot = "0500993881";
google_ad_width = 468;
google_ad_height = 60;
//--&gt;
&lt;/script&gt;

&lt;script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"&gt;
&lt;/script&gt;</description>
      <pubDate>Fri, 12 Dec 2008 02:00:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:3c5dcfc7-54c1-4633-8e4b-f4ea54ea3894</guid>
      <author>azimux@gmail.com (miles)</author>
      <comments>http://nopugs.com/2008/12/12/how-to-debug-an-individual-rails-test-in-netbeans#comments</comments>
      <category>Ruby on Rails</category>
      <category>Netbeans</category>
      <trackback:ping>http://nopugs.com/trackbacks?article_id=14</trackback:ping>
      <link>http://nopugs.com/2008/12/12/how-to-debug-an-individual-rails-test-in-netbeans</link>
    </item>
  </channel>
</rss>
