NealR
NealR

Reputation: 10679

Rspec says implemented method is not implemented

Below is an rspec test I'm running to test another class I've made. Unfortunately the method I'm trying to test (delete) does not seem to be working. What's throwing me is that the error message I'm getting from the Termianl is:

/Users/user/Ruby/localWikiClient/localwiki_client/spec/delete_spec:11:in 'block (2 levels) in <top (required)>': undefined method 'delete' for #<Proc:0x007fe4739a5448> (NoMethodError)

However, this method is defined in the class. Below is the code:

require 'faraday'
require 'json/pure'

module Localwiki

  ##
  # A client that wraps the localwiki api for a given server instance
  #
  class Client

    attr_accessor :hostname       # hostname of the server we'd like to point at
    attr_reader   :site_name      # site resource - display name of wiki
    attr_reader   :time_zone      # site resource - time zone of server, e.g. 'America/Chicago'
    attr_reader   :language_code  # site resource - language code of the server, e.g. 'en-us'

    def initialize hostname, user=nil, apikey=nil
      @hostname = hostname
      @user = user
      @apikey = apikey
      create_connection
      collect_site_details
    end

   ##
   # Get site resource and set instance variables
   #
   def collect_site_details
       site = fetch('site','1')
       @site_name = site['name']
       @time_zone = site['time_zone']
       @language_code = site['language_code']
   end

   ##
   # create Faraday::Connection instance and set @site
   #
   def create_connection
      @site = Faraday.new :url => @hostname
   end

   ##
   # delete a specific resource
   # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
   # identifier is id, pagename, slug, etc.
  def delete(resource,identifier)
    case resource
    when resource == "site"
      @hostname = identifier
      create_connection
    when resouce == "user"
      @hostname = list(identifier)   
    end  

    http_delete()
  end

  def http_delete()
    response = @site.delete
    puts response.to_s
  end

Here's the rspec test I'm trying to run:

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require 'localwiki_client'

describe '<siteinfo>.amazonaws.com/bears' do

  subject { Localwiki::Client.new '<siteinfo>.compute-1.amazonaws.com/bears', '<username>', '[myApiKey]' }

  context '#fetch' do
    subject.delete('page', 'bears')
  end

end

Upvotes: 0

Views: 706

Answers (1)

Peter Brown
Peter Brown

Reputation: 51697

You can't access the subject like that within a context block. You will need to either put it in a before block or within an actual test block (it/specify):

describe '<siteinfo>.amazonaws.com/bears' do

  subject { Localwiki::Client.new '<siteinfo>.compute-1.amazonaws.com/bears', '<username>', '[myApiKey]' }

  context '#fetch' do
    it "deletes the bears page" do
      subject.delete('page', 'bears')
    end
  end

end

Upvotes: 4

Related Questions