title: How do I call a module method in rspec, with the current module set up
body: <p>So I have the following module for handling the fetching of and saving of tweets. This is all done on a thread, I am interested in testing two methods with in this module: <code>fetch_tweets</code> and <code>save_tweets</code></p>
  
  <p>For <code>fetch_tweets</code>, I want to validate that the <code>save_tweets</code> method is called. I don't care what it returns.</p>
  
  <p>For the <code>save_tweets</code>, I want to test that a tweet is actually saved.</p>
  
  <p>So with that in mind, lets look at some code.</p>
  
  <p><strong>Twitter::TwitterHandler</strong> - This lives in <code>lib/twitter/twitter_handler.rb</code></p>
  
  <pre><code>module Twitter
    module TwitterHandler
  
      def handle_tweets(twitter_client_object)
        Thread.new do
          begin
            twitter_lock(twitter_client_object)
          ensure
            ActiveRecord::Base.clear_active_connections!
          end
        end
      end
  
      def twitter_lock(twitter_client_object)
        TwitterTweet.with_advisory_lock('aisis-writer-tweets', 0) do
          fetch_tweets(twitter_client_object)
        end
      end
  
      def fetch_tweets(twitter_client_object)
        Rails.cache.fetch([:aisis_twitter_feed, Time.now.to_i/60/5], expires_in: 1.minute){
          twitter_client.user_timeline(user_id: '252157965', count: 100).map(&amp;:as_json).select{ |h| h["text"].match(/aisiswriter/i) }.take(10).each do |tweet|
            save_tweets(tweet['id_str'], tweet['text'], tweet['created_at'])
          end
        }
      end
  
      def save_tweets(id, text, created_at)
        tweet = TwitterTweet.find_or_initialize_by(id: id)
        tweet.text = text
        tweet.created_at = created_at
        tweet.save
      end
  
    end
  end
  </code></pre>
  
  <p><strong>twitter_handler_spec.rb</strong> - This lives in spec/twitter/twitter_handler_spec.rb</p>
  
  <pre><code>require 'rails_helper'
  require_relative '../../lib/twitter/twitter_handler'
  
  describe 'TwitterHandler' do
  
    context "fetch tweets method" do
      it "should fetch some tweets" do
        t = Time.parse("01/01/2010 10:00")
        Time.should_receive(:now).and_return(t)
        expect(fetch_tweets(twitter_client)).to receive(:save_tweets).with('342', 'Something', t).and_return nil
      end
    end
  end
  </code></pre>
  
  <p>When I run <code>bin/rspec spec/twitter/twitter_handler_spec.rb</code> I get:</p>
  
  <pre><code>Failures:
  
    1) TwitterHandler fetch tweets method should fetch some tweets
       Failure/Error: expect(fetch_tweets(twitter_client)).to receive(:save_tweets).with('342', 'Something', t).and_return nil
       NoMethodError:
         undefined method `fetch_tweets' for #&lt;RSpec::ExampleGroups::TwitterHandler::FetchTweetsMethod:0x007ff1c724e300&gt;
       # ./spec/twitter/twitter_handler_spec.rb:11:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>How do I fix this, so I can call this method and any other method in this module?</p>