-1

I'm very new to Ruby and and RSpec. I would like to create basic Spec file for this module:

module DownloadAttemptsHelper

  def download_attempt_filter_select_options
    search_types = [
      [I18n.t("helpers.download_attempts.search_types_default"),          'default'          ],
      [I18n.t("helpers.download_attempts.search_types_account_id"),      'account_id'      ],
      [I18n.t("helpers.download_attempts.search_types_remote_ip"),        'remote_ip'        ],
    ]
    options_for_select(search_types)
  end
end

Small test

describe DownloadAttemptsHelper do
  it "does something" do
    expect(1).to be_odd
  end
end

I get:

`<top (required)>': uninitialized constant DownloadAttemptsHelper (NameError)

Do I need to import the directory path and module name? Can you give me some very basic example how I can test this module?

Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

2 Answers2

0

If you're using Rails, you need to make sure your module is being loaded when the server starts. Open up a rails c and check if you can access your module there. If not, you can do something like described here Auto-loading lib files in Rails 4

That is, make Rails autoload classes in the lib directory, if that's where your helper is located in.

Community
  • 1
  • 1
Coolness
  • 1,932
  • 13
  • 25
-1

You have to include the module in the rspec test file to make it's methods available in the test cases:

describe "DownloadAttemptsHelper" do
  include DownloadAttemptsHelper

  it "does something" do
    expect(1).to be_odd
  end
end
  • I get again the same error: ``': uninitialized constant DownloadAttemptsHelper (NameError)`. Probably I need to specify directory and file location? – Peter Penzov Jan 05 '17 at 15:43