<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title>Austintech</title>
  <link href="http://austintech.com/atom.xml" rel="self"/>
  <link href="http://austintech.com/"/>
  <updated>2012-01-31T05:24:35-05:00</updated>
  <id>http://austintech.com/</id>
  <author>
    <name>Patrick Ward</name>
    
  </author>

  
  <entry>
    <title>Moving</title>
    <link href="http://austintech.com/blog/2012/01/31/moving/"/>
    <updated>2012-01-31T05:18:00-05:00</updated>
    <id>http://austintech.com/blog/2012/01/31/moving</id>
    <content type="html">&lt;p&gt;I've decided to move all of my online material over to my namesake site at &lt;a href=&quot;http://patrickward.com&quot;&gt;patrickward.com&lt;/a&gt;. It's easier for me to manage and uses my new &lt;a href=&quot;https://github.com/patrickward/willow&quot;&gt;Willow&lt;/a&gt; generator. Octopress was great, but still awkward to use for my purposes. The new set up is getting closer to what I originally wanted.&lt;/p&gt;

&lt;p&gt;See you over there.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>How I Use Compass With Rails 3.1</title>
    <link href="http://austintech.com/blog/2011/08/19/how-i-use-compass-with-rails-3-1/"/>
    <updated>2011-08-19T06:22:00-04:00</updated>
    <id>http://austintech.com/blog/2011/08/19/how-i-use-compass-with-rails-3-1</id>
    <content type="html">&lt;p&gt;For one of my ongoing projects, I'm using the latest version of Rails (3.1.0.rc6 as of this post) along with the &lt;a href=&quot;http://compass-style.org&quot;&gt;Compass&lt;/a&gt; CSS framework. At first, this turned out to be an adventure in maintaining a calm composure. But, my experience of the Rails Asset Pipeline coupled with the Compass framework is proving to be worth the effort.&lt;/p&gt;

&lt;h2&gt;My First Approach&lt;/h2&gt;

&lt;p&gt;My first approach to the problem was to keep them completely separate. I generated a Compass project outside of the asset pipeline folders and set it's config parameters to generate CSS files within the normal &lt;em&gt;app/assets/stylesheets&lt;/em&gt; folder under rails. The setup was essentially like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;RAILS_ROOT
  + compass/
    + sass/
      style.scss
      _layout_partial.scss
      _some_other_partial.scss
      _etc... 
  + app/
    + assets/
      + stylesheets/
        application.css
        style.css
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Using &lt;a href=&quot;https://github.com/guard/guard&quot;&gt;Guard&lt;/a&gt; or &lt;code&gt;compass watch&lt;/code&gt; on the command line I would essentially pre-compile the Compass CSS files. Using the default Rails application.css file, Sprockets would then pick up the pre-compiled style.css file for use within the Rails framework.&lt;/p&gt;

&lt;p&gt;While this worked, it was hackish and required additional steps to complete. Thankfully, the &lt;a href=&quot;https://github.com/rails/rails&quot;&gt;Rails&lt;/a&gt;, &lt;a href=&quot;https://github.com/rails/sass-rails&quot;&gt;sass-rails&lt;/a&gt;, and &lt;a href=&quot;https://github.com/chriseppstein/compass&quot;&gt;Compass&lt;/a&gt; projects have all come a long way in the past few months.&lt;/p&gt;

&lt;h2&gt;My New Approach&lt;/h2&gt;

&lt;p&gt;I've since abandoned the idea of using Compass outside of the asset pipeline and now use it coupled with Sprockets own require system. In addition to the latest versions of the Compass and Rails projects, an understanding of how Sprockets and the asset pipeline work is essential to making this work.&lt;/p&gt;

&lt;h3&gt;Use the right version of Compass&lt;/h3&gt;

&lt;p&gt;To begin with, I found it necessary to use the git version of the rails31 branch of Compass, which seems to have some fixes for using it with Rails 3.1 conventions. Here's a summary of the key Gemfile adjustments I've made recently to get things kickstarted.&lt;/p&gt;

&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;Gemfile.rb &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;span class='line'&gt;5&lt;/span&gt;
&lt;span class='line'&gt;6&lt;/span&gt;
&lt;span class='line'&gt;7&lt;/span&gt;
&lt;span class='line'&gt;8&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='rb'&gt;&lt;div class='line'&gt;&lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;rails&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;3.1.0.rc6&amp;#39;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:assets&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;sass-rails&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;~&amp;gt; 3.1.0.rc&amp;quot;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;coffee-rails&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;~&amp;gt; 3.1.0.rc&amp;quot;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;uglifier&amp;#39;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;n&quot;&gt;gem&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;compass&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:git&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;https://github.com/chriseppstein/compass.git&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:branch&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;rails31&amp;quot;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;


&lt;h3&gt;Sprockets vs Sass vs Compass&lt;/h3&gt;

&lt;p&gt;At this point, I needed to understand the key differences betweeen Sprockets, Sass, and Compass.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Sprockets&lt;/strong&gt; is essentially a pre-processor and rails uses it to stitch together your CSS files into a single, monolithic stylesheet. While it recognizes and precompiles (or filters) &lt;strong&gt;Sass&lt;/strong&gt; files, it's require system does not understand the concept of Sass partials or mixins through the use of imports and includes. So, you have to separate the logic used in Sass from the logic used in Sprockets. There is a linear process that you must be aware of when working with the two that looks something like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Rails starts up the asset pipeline (or sprockets), which begins to read in the &quot;required&quot; files you specified&lt;/li&gt;
&lt;li&gt;When it finds a .sass or .scss file in it's require path, it passes that file off to Sass for rendering. (&lt;em&gt;This is true for any file that requires additional processing, such as .erb files.&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;Sass then uses it's own rendering engine to import, include, and process partials, variables, etc. This is separate and outside the scope of what Sprockets does. So, if you want to reference Sass variables or mixins in different files, you need to ensure that the proper Sass @import calls have been made in those files.&lt;/li&gt;
&lt;li&gt;Sprockets then stitches all of the rendered files it finds back into it's own process using the separate logic of its require system.&lt;/li&gt;
&lt;/ol&gt;


&lt;blockquote&gt;&lt;p&gt;The key distiction here is that Sprockets does not render Sass files, it filters them through Sass before including them back into it's own require system. They are separate and distinct in their knowledge of each other.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;For &lt;strong&gt;Compass&lt;/strong&gt;, remember that, at heart, it is a collection of Sass mixins. When used this way, you can create a folder structure that keeps Sass and Sprockets logically and visually separated.&lt;/p&gt;

&lt;h3&gt;Separating Sass from Sprockets&lt;/h3&gt;

&lt;p&gt;What helped me was physically separating the Sass based code from the Sprocket requires. This is not the standard way that the Rails 3.1 generators expect you to use the asset pipeline, but it made more sense to me for several reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I tend to organize my Compass/Sass files in heirarchical order which depends on a liberal use of @import and @include for mixins&lt;/li&gt;
&lt;li&gt;I felt I had more control over the order of requires and the process that Sprockets uses to include files.&lt;/li&gt;
&lt;li&gt;I liked the visual and physical separation of CSS code&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The folder structure for my most recent project ended up looking similar to the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;RAILS_ROOT
  + app/
    + assets/
      + stylesheets/
        application.css
        + application/ 
          application.css.scss
          _base.scss
          _buttons.scss
          ...
          _layout.scss
          _menu.scss
          _users.scss
          etc...
        + aristo/ 
          jquery.ui.all.css.scss
          _base.scss
          _button.scss
          etc..
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This enabled me to separate key areas of the application's CSS and use the Compass framework, along with the full capabilities of Sass, without worrying about how Sprockets was going to pull in each of my files.&lt;/p&gt;

&lt;h3&gt;Removing require_tree&lt;/h3&gt;

&lt;p&gt;Rails puts a few magical requires into the default application.css, which at first seem perfectly reasonable, until you start using it the way I'm describing here. Then, it becomes a bit of a hassle.&lt;/p&gt;

&lt;p&gt;So, my first order of business was to remove the &lt;code&gt;require_tree&lt;/code&gt; directive from my application.css file. That directive requires all stylesheets from the current directory at the location of the directive. Since I am trying to have more control over how stylesheets are ordered in my application, that directive doesn't help me. So, out it goes and in go more specific requires based on my folder structure above.&lt;/p&gt;

&lt;h3&gt;Adding application.css.scss&lt;/h3&gt;

&lt;p&gt;I like to structure my Compass files using a primary css file that pulls in additional partials as needed. This led me to creating the application.css.scss file underneath the &lt;em&gt;application&lt;/em&gt; subdirectory: &lt;code&gt;application/application.css.scss&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Rather than use Rails generated scss files (e.g. users.css.scss for a users_controller), I opted to use partials underneath the application directory and pull them into the main application.css.scss file instead. This gives me greater control over the order of files that are imported and let's me use Compass and Sass the way that I'm used to using them. &lt;strong&gt;In fact, when Rails generates the users.css.scss file, I just delete it before I make a commit to git.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the application.css.scss file becomes a mid-level processor for my Compass structured css:&lt;/p&gt;

&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;application.css.scss &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;span class='line'&gt;5&lt;/span&gt;
&lt;span class='line'&gt;6&lt;/span&gt;
&lt;span class='line'&gt;7&lt;/span&gt;
&lt;span class='line'&gt;8&lt;/span&gt;
&lt;span class='line'&gt;9&lt;/span&gt;
&lt;span class='line'&gt;10&lt;/span&gt;
&lt;span class='line'&gt;11&lt;/span&gt;
&lt;span class='line'&gt;12&lt;/span&gt;
&lt;span class='line'&gt;13&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='scss'&gt;&lt;div class='line'&gt;&lt;span class=&quot;c1&quot;&gt;// Framework&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;compass/reset&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;compass/css3&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;susy&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c1&quot;&gt;// Application &lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;base&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;defaults&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;layout&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c1&quot;&gt;// etc... &lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c1&quot;&gt;// Controllers &lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;k&quot;&gt;@import&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;users&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;


&lt;p&gt;I can now use Compass and Sass the way I like to without worrying about how the Rails asset pipeline is going to see them.&lt;/p&gt;

&lt;h3&gt;But, What About the application.css file?&lt;/h3&gt;

&lt;p&gt;Let's not forget that we're still using Sprockets. As I mentioned earlier, I take out the &lt;code&gt;require_tree&lt;/code&gt; directive and replace it with specific requires for the Sass files I'm interested in including into my manifest.&lt;/p&gt;

&lt;p&gt;In my case I'm adding both an application css file along with a jQuery UI file I converted to Sass for use in my application.&lt;/p&gt;

&lt;p&gt;I keep the &lt;code&gt;require_self&lt;/code&gt; directive, which leaves my application.css file looking similar to the following:&lt;/p&gt;

&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;application.css &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;span class='line'&gt;5&lt;/span&gt;
&lt;span class='line'&gt;6&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='css'&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;/*&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt; *= require_self&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt; *= require &amp;quot;aristo/jquery.ui.all&amp;quot;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt; *= require &amp;quot;application/application&amp;quot;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt; *= require &amp;quot;some_additional_css_file&amp;quot;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;*/&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;


&lt;p&gt;At this point, I can add additional plain css files, Sass files, vendor files, etc. all within the boundaries of how my application expects them to be ordered (i.e. required). An example of that is the use of my customized jquery.ui.all file that I'm requiring outside of my Compass framework.&lt;/p&gt;

&lt;h2&gt;Summary&lt;/h2&gt;

&lt;p&gt;This approach allows me to use the best of Compass and Sass along with the flexibility (and Rails oriented way) of the asset pipeline (or Sprockets), but without having to sacrifice the tried and true method that Compass users are used to.&lt;/p&gt;

&lt;p&gt;Condensed into a few easy steps, the process is:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use the rails31 branch of the Compass gem in your Gemfile.&lt;/li&gt;
&lt;li&gt;Separate your application's Compass/Sass files from Sprockets (e.g. I use a folder structure)&lt;/li&gt;
&lt;li&gt;Remove the Rails generated css.scss files and use partials with Compass instead&lt;/li&gt;
&lt;li&gt;Remove the &lt;code&gt;require_tree&lt;/code&gt; directive from application.css&lt;/li&gt;
&lt;li&gt;Add your additional Sass or CSS files using regular &lt;code&gt;require&lt;/code&gt; directives in application.css&lt;/li&gt;
&lt;/ol&gt;

</content>
  </entry>
  
  <entry>
    <title>Techniques to Clear Floats in CSS</title>
    <link href="http://austintech.com/blog/2011/08/17/techniques-to-clear-floats-in-css/"/>
    <updated>2011-08-17T06:07:00-04:00</updated>
    <id>http://austintech.com/blog/2011/08/17/techniques-to-clear-floats-in-css</id>
    <content type="html">&lt;p&gt;I ran into the pervavise issue of having to clear a DIV that contains only floated DIV elements in it recently. The problem is that the outer container does not stretch to accomodate the height of it's child containers. So, if you have a background or a border on the containing element, it does not fully cover the child elements.&lt;/p&gt;

&lt;p&gt;It's an old issue, but I keep forgetting where to find the information on how to fix it. So, this is a note to self for future reference.&lt;/p&gt;

&lt;p&gt;I found the following resources to be the most useful in terms of the pros and cons of each technique. Please see them for more detailed instruction. I've summarized the basics below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See &lt;a href=&quot;http://stackoverflow.com/questions/4701015/css-clearing-floats&quot;&gt;CSS Clearing Floats on Stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;See &lt;a href=&quot;http://www.quirksmode.org/css/clearing.html&quot;&gt;Clearing Floats on Quirksmode&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;See &lt;a href=&quot;http://stackoverflow.com/questions/211383/which-method-of-clearfix-is-best&quot;&gt;Which Method of 'clearfix' is Best? on Stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;See &lt;a href=&quot;http://www.positioniseverything.net/easyclearing.html&quot;&gt;How to Clear Floats Without Structural Markup&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Add an Empty DIV and clear:both Styling&lt;/h2&gt;

&lt;p&gt;The easiest, and oldest, fix is to add an empty DIV with a style of &lt;em&gt;clear:both&lt;/em&gt; to the end of the outer container. This works, but it's not semantic and makes a mess of the page's markup.&lt;/p&gt;

&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;sample.css &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='css'&gt;&lt;div class='line'&gt;&lt;span class=&quot;nf&quot;&gt;#container&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;border&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1px&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;solid&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;#000000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nf&quot;&gt;#left&lt;/span&gt;   &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nf&quot;&gt;#right&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;45&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;float&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nc&quot;&gt;.clear&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;both&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;




&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;sample.html &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;span class='line'&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;div class='line'&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;container&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;left&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Lorem ipsum...&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;right&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Lorem ipsum...&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;clear&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;


&lt;h2&gt;Use the clearfix Hack&lt;/h2&gt;

&lt;p&gt;Beyond adding additional markup to the page, you can use the infamous 'clearfix' hack, which cheats by adding additional content &lt;em&gt;after&lt;/em&gt; the containing element. While this prevents you from having to muddy the markup on the page, it feels a bid hackish to me.&lt;/p&gt;

&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;sample.css &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;span class='line'&gt;5&lt;/span&gt;
&lt;span class='line'&gt;6&lt;/span&gt;
&lt;span class='line'&gt;7&lt;/span&gt;
&lt;span class='line'&gt;8&lt;/span&gt;
&lt;span class='line'&gt;9&lt;/span&gt;
&lt;span class='line'&gt;10&lt;/span&gt;
&lt;span class='line'&gt;11&lt;/span&gt;
&lt;span class='line'&gt;12&lt;/span&gt;
&lt;span class='line'&gt;13&lt;/span&gt;
&lt;span class='line'&gt;14&lt;/span&gt;
&lt;span class='line'&gt;15&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='css'&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;/* This fixes the problem for most browsers */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nc&quot;&gt;.clearfix&lt;/span&gt;&lt;span class=&quot;nd&quot;&gt;:after&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;content&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;.&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;clear&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;both&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;visibility&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;hidden&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;/* This fixes the problem for IE7 */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nc&quot;&gt;.clearfix&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;min-height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;/* This fixes the problem for IE6 */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;.clearfix&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;


&lt;h2&gt;Use the overflow:hidden Technique&lt;/h2&gt;

&lt;p&gt;The method I've tended to use and that has the least problems in my experience is the &lt;em&gt;overflow&lt;/em&gt; method, with some additional css to trigger &lt;a href=&quot;http://www.satzansatz.de/cssd/onhavinglayout.html&quot;&gt;hasLayout&lt;/a&gt; in IE.&lt;/p&gt;

&lt;p&gt;This method works great as long as there is no fixed height on the outer container. See &lt;a href=&quot;http://www.quirksmode.org/css/clearing.html&quot;&gt;Quirksmode&lt;/a&gt; for ways to resolve issues related to this technique.&lt;/p&gt;

&lt;p&gt;I've seen some references indicate that you can use &lt;em&gt;overflow:auto&lt;/em&gt; to achieve the same results, but you risk having scrollbars show. So far, the &lt;em&gt;overflow:hidden&lt;/em&gt; method has been the cleanest and most efficient technique for me.&lt;/p&gt;

&lt;div&gt;&lt;figure role=code&gt;&lt;figcaption&gt;&lt;span&gt;sample.css &lt;/span&gt;&lt;/figcaption&gt;
 &lt;div class=&quot;highlight&quot;&gt;&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre class=&quot;line-numbers&quot;&gt;&lt;span class='line'&gt;1&lt;/span&gt;
&lt;span class='line'&gt;2&lt;/span&gt;
&lt;span class='line'&gt;3&lt;/span&gt;
&lt;span class='line'&gt;4&lt;/span&gt;
&lt;span class='line'&gt;5&lt;/span&gt;
&lt;span class='line'&gt;6&lt;/span&gt;
&lt;span class='line'&gt;7&lt;/span&gt;
&lt;span class='line'&gt;8&lt;/span&gt;
&lt;span class='line'&gt;9&lt;/span&gt;
&lt;span class='line'&gt;10&lt;/span&gt;
&lt;span class='line'&gt;11&lt;/span&gt;
&lt;span class='line'&gt;12&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code' width='100%'&gt;&lt;pre&gt;&lt;code class='css'&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;/* Cleanest method */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nc&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;hidden&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inline&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;/* Necessary to trigger &amp;quot;hasLayout&amp;quot; in IE */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;/* Sets element back to block */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;c&quot;&gt;/* Or, use the zoom method to trigger &amp;quot;hasLayout&amp;quot; in IE */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;nc&quot;&gt;.container&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;overflow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;hidden&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;n&quot;&gt;zoom&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;m&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;/* Necessary to trigger &amp;quot;hasLayout&amp;quot; in IE */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;  &lt;span class=&quot;k&quot;&gt;display&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;block&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;/* Sets element back to block */&lt;/span&gt;
&lt;/div&gt;&lt;div class='line'&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/div&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;&lt;/div&gt;



</content>
  </entry>
  
  <entry>
    <title>Understanding Subject in RSpec 2</title>
    <link href="http://austintech.com/blog/2011/08/15/understanding-subject-in-rspec-2/"/>
    <updated>2011-08-15T05:41:00-04:00</updated>
    <id>http://austintech.com/blog/2011/08/15/understanding-subject-in-rspec-2</id>
    <content type="html">&lt;p&gt;I needed to write some shared examples in RSpec the other day for a simple ActiveRecord concern I was writing.&lt;/p&gt;

&lt;p&gt;In doing so, it forced me to understand what RSpec means by the &quot;subject&quot; of an example. I'll admit this is a very simple concept, but until now I didn't take the time to understand it and the &lt;a href=&quot;http://relishapp.com/rspec/rspec-core&quot;&gt;relish docs&lt;/a&gt; weren't overly descriptive on how it works.&lt;/p&gt;

&lt;p&gt;In general, the &lt;em&gt;subject&lt;/em&gt; of an example is just &lt;strong&gt;the object being described&lt;/strong&gt;. But what, specifically, does that mean?&lt;/p&gt;

&lt;p&gt;In an implicit context, it means the subject is an &lt;em&gt;instance&lt;/em&gt; of the object being described. For example, in a model spec, I might be describing a User class:&lt;/p&gt;

&lt;p&gt;``` Ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;describe User do
  it { should respond_to :authenticate }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;Which can also be written as:&lt;/p&gt;

&lt;p&gt;``` Ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;describe User do
  subject.should respond_to :authenticate
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;Here, the &lt;em&gt;subject&lt;/em&gt; is an instance of User. RSpec creates an instance of User by calling new on the User class without any arguments. It's the same as saying this:&lt;/p&gt;

&lt;p&gt;``` Ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;describe User do
  subject { User.new }
  it { should respond_to :authenticate }
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;That last example, is what RSpec calls an &lt;strong&gt;explicit subject&lt;/strong&gt;. Instead of deducing the subject from the outer describe, an &lt;em&gt;explicit subject&lt;/em&gt; is declared within the example and can be used afterwards the same way that an &lt;em&gt;implicit subject&lt;/em&gt; would.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;The key distinction for me, and one that I didn't understand previously, was that the &lt;em&gt;subject&lt;/em&gt; is an &lt;strong&gt;instance&lt;/strong&gt; of the class being described (implicitly or explicitly).&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;This came up when I needed to test both an instance of a subject as well as a static class method of a subject's parent class.&lt;/p&gt;

&lt;h2&gt;But how do I test a static class method against an instance?&lt;/h2&gt;

&lt;p&gt;Simple, just call &lt;em&gt;class&lt;/em&gt; on the instance.&lt;/p&gt;

&lt;p&gt;``` Ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;describe User do
  subject.class.some_class_method.should do_something
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;It's all very simple, but I just hadn't grokked it until now. Fortunately, this realization came in handy when I was writing a simple shared example to test common functionality against multiple models.&lt;/p&gt;

&lt;p&gt;In this case I wanted to test that a model had a specific instance method as well as some class-based scopes.&lt;/p&gt;

&lt;p&gt;``` Ruby&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;shared_examples_for &quot;a Trashable&quot; do |model_type|

  before(:each) do
    @objects = [
      Factory(model_type, :trashed =&amp;gt; false),
      Factory(model_type, :trashed =&amp;gt; true)
    ]
  end

  it &quot;should respond to a trash method&quot; do
    subject.should respond_to :trash
  end

  # Note - have to call class on the implicit subject to call a class method! 
  it &quot;should not show trashed subjects by default&quot; do
    subject.class.all.should_not include(@objects.second)
  end

  it &quot;should show trashed subjects&quot; do
    subject.class.trashed.should include(@objects.second)
    subject.class.trashed.should_not include(@objects.first)
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;By using &lt;em&gt;subject&lt;/em&gt; and passing in the model_type to generate some factories, I'm able to dynamically adjust to whatever model the shared example exists within at the time. Simple, dry, and efficient.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Installing PHPUnit With MAMP 2.0.1</title>
    <link href="http://austintech.com/blog/2011/08/07/installing-phpunit-with-mamp-2-0-1/"/>
    <updated>2011-08-07T08:51:00-04:00</updated>
    <id>http://austintech.com/blog/2011/08/07/installing-phpunit-with-mamp-2-0-1</id>
    <content type="html">&lt;p&gt;I needed to install PHPUnit with my local version of MAMP Pro 2.0.1 recently. After starting with this article for ideas, I came up with the following adjusted steps:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Create a soft link to the MAMP version of pear:&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ln -s /Applications/MAMP/bin/php/php5.3.6/bin/pear \
/usr/local/bin/pear
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; I found that the default pear.conf file was either corrupt or invalid. Following a forum suggestion on the mamp.info site, I just removed it by renaming it:&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf \
/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bak
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; Add the pear channels associated with PHPUnit:&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pear channel-discover pear.phpunit.de
pear channel-discover pear.symfony-project.com
pear channel-discover components.ez.no
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; Install PHPUnit:&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pear install phpunit/PHPUnit
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: I ran into a an issue at this point, where pear would not install an unstable version of HTTP_Request2 that it found. So, I just forced it to install the RC1 version instead:&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;pear install -f HTTP_Request2-2.0.0RC1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I ran the pear install command after this.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; At this point, PHPUnit should be installed. So, I created a new soft link to the phpunit file:&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ln -s /Applications/MAMP/bin/php/php5.3.6/bin/phpunit \
/usr/local/bin/phpunit
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; Done. To test the install type:&lt;/p&gt;

&lt;p&gt;``` bash&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;phpunit --version
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;```&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introduction</title>
    <link href="http://austintech.com/blog/2011/08/07/introduction/"/>
    <updated>2011-08-07T08:32:00-04:00</updated>
    <id>http://austintech.com/blog/2011/08/07/introduction</id>
    <content type="html">&lt;p&gt;This blog is a place for me to store notes to myself that are technical in nature. Hopefully, my notes will be useful to you as well. Feel free to browse around.&lt;/p&gt;
</content>
  </entry>
  
</feed>

