1

I have this code for unit test:

require 'rails_helper'
require 'fetch_controller'

   RSpec.describe FetchController, type: :controller do
   it "parse base 64 url" do
     result = FetchController.parse_urls('aHR0cDovL3d3dy5nb29nbGUuY29t')

    expect(result[0]).to eq('http://www.google.com')

   end
 end

and I want to test parse_urls method that in fetch_controller:

class FetchController < ApplicationController
...
  def parse_urls(base)
  Base64.decode64(base).split(',')
end

But when i'm trying to run it I get an error ": in `require': cannot load such file -- fetch_controller (LoadError)"

Thanks for any help, Yoel

9
  • Did you try to remove require 'fetch_controller' line? Commented Aug 31, 2015 at 8:31
  • have you written file named 'fetch_controller'.? Commented Aug 31, 2015 at 8:34
  • I have fetch_controller under the app. Should I write another one under spec? and if so, what should I write in the file: ' class FetchController def initialize end end ' I din't understand how to initialize it. Thanks! Commented Aug 31, 2015 at 8:53
  • @Joel you shouldn't require controllers by hand, it should be done by rspec. Commented Aug 31, 2015 at 8:54
  • @dimakura, I removed the require controller but I get uninitialized constant FetchController Commented Aug 31, 2015 at 8:55

1 Answer 1

1

Ok, so you use a namespace. Then, proper names are

class Api::FetchController < ApplicationController

and

RSpec.describe Api::FetchController, type: :controller do
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.