title: Rspec "NoMethodError"
body: <p>I'm new to Unit Testing in Ruby using RSpec and I'm having trouble performing a very basic Unit test. I'm used to unit testing in Python and JavaScript, and I usually don't run into this problem.</p>
  
  <p>I'm simply trying to test a STDOUT using the puts statement. Here is my spec.</p>
  
  <p><code>my_spec.rb</code></p>
  
  <pre><code>require 'my_file'
  
    describe C do
      before(:all) do
        @c = C.new
      end
  
      describe C do
        subject(:C) { described_class.new }
        it 'should print Hello World' do
          expect {@c.main}.to output("Hello world").to_stdout
        end
      end
    end
  </code></pre>
  
  <p>Here is <code>my_file.rb</code></p>
  
  <pre><code>class C
      def main
          puts "Hello World"
      end
  end
  </code></pre>
  
  <p>No major code here, just a simple test for Output, but I'm receiving the an <code>NoMethodError</code> error when I run my spec:</p>
  
  <pre><code>Failures:
  
    1) C C should print Hello World
       Failure/Error: expect {@c.main}.to output("Hello world").to_stdout
  
       NoMethodError:
         undefined method `main' for #&lt;C:0x007fe54488a550&gt;
       # ./spec/my_spec.rb:12:in `block (4 levels) in &lt;top (required)&gt;'
       # ./spec/my_spec.rb:12:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>It says I have an undefined method <code>main</code> when I do have it defined in <code>my_file.rb</code>, what I do know about this error is it's usually due to me calling a method before it's defined. Not to sure what I'm doing wrong here though since I thought the method is defined. Any help is greatly appreciated! </p>