stevehodgkiss/generator_spec

undefined method `destination' for #<Class:0x007f8a04272938>

Closed this issue · 3 comments

Hi,
I'm creating a gem that includes a generator, would like to use this for testing. However, when I run rspec, I am getting the following error:

/Users/Justin/Dropbox/Documents/Rails/webpush/spec/lib/generators/install_generator_spec.rb:5:in `block in <top (required)>': undefined method `destination' for #<Class:0x007f8a04272938> (NoMethodError)
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/example_group.rb:246:in `module_eval'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/example_group.rb:246:in `subclass'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/example_group.rb:232:in `describe'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/dsl.rb:18:in `describe'
from /Users/Justin/Dropbox/Documents/Rails/webpush/spec/lib/generators/install_generator_spec.rb:4:in `<top (required)>'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `block in load'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:236:in `load_dependency'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:245:in `load'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `each'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/command_line.rb:22:in `run'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/runner.rb:80:in `run'
from /Users/Justin/.rvm/gems/ruby-2.0.0-p247@rails4/gems/rspec-core-2.14.6/lib/rspec/core/runner.rb:17:in `block in autorun'

My spec_helper.rb:

ENV["RAILS_ENV"] = "test"

require File.expand_path("../dummy/config/environment.rb",  __FILE__)

require 'rubygems'
require 'bundler/setup'
require 'capybara/rails'
require 'capybara/rspec'
require 'generator_spec'

RSpec.configure do |config|
    config.include Capybara::DSL
end

Gemspec:

# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'webpush/version'

Gem::Specification.new do |spec|
  spec.name          = "webpush"
  spec.version       = Webpush::VERSION
  spec.authors       = ["Justin Chapman"]
  spec.email         = ["commonmodestudio@gmail.com"]
  spec.description   = %q{TODO: Write a gem description}
  spec.summary       = %q{TODO: Write a gem summary}
  spec.homepage      = ""
  spec.license       = "MIT"

  spec.files         = `git ls-files`.split($/)
  spec.executables   = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
  spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
  spec.require_paths = ["lib"]

  spec.add_dependency "coffee-script", "~> 2.2.0"
  spec.add_dependency 'railties', '>= 3.1.0'

  spec.add_development_dependency "bundler", "~> 1.3"
  spec.add_development_dependency "rake"
  spec.add_development_dependency 'rails', '~> 3.2.0'
  spec.add_development_dependency "rspec", "~> 2.14.1"
  spec.add_development_dependency "rails-dummy"
  spec.add_development_dependency 'sqlite3'
  spec.add_development_dependency 'capybara'
  spec.add_development_dependency 'generator_spec'
end

The spec:

require 'spec_helper'
require 'generators/webpush/install_generator'

describe Webpush::Generators::InstallGenerator do
destination File.expand_path("../../tmp",  __FILE__)

before :all do
    prepare_destination
    run_generator
end

  it "copies pushpackage folder" do
    pending 'todo'
  end
end

I think you need to include the GeneratorSpec::TestCase in your spec file.

require 'spec_helper'
require 'generator_spec/test_case'
require 'generators/webpush/install_generator'

describe Webpush::Generators::InstallGenerator do
  include GeneratorSpec::TestCase

  destination File.expand_path("../../tmp",  __FILE__)

  before :all do
    prepare_destination
    run_generator
  end

  it "copies pushpackage folder" do
    pending 'todo'
  end
end

Thanks Murphyslaw - you really need to include what you posted in the ReadMe - it's exactly what I needed!

simi commented

@parndt can be closed!