Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

routes specs #10

Open
rafamvc opened this issue Jun 13, 2012 · 3 comments
Open

routes specs #10

rafamvc opened this issue Jun 13, 2012 · 3 comments

Comments

@rafamvc
Copy link

rafamvc commented Jun 13, 2012

I tried to test the route method of generator and it doesn't work.

route "get 'my_controller#my_action'"

Maybe I missed the documentation entry but I couldn't find.

@alexrothenberg
Copy link
Owner

You're right there is no documentation for this because I've never tried it before :)

You can get it to work if you write a spec like:

require "spec_helper"
require 'generators/routing/routing_generator'

describe RoutingGenerator do
  destination Rails.root + 'tmp/generated_files'

  before do
    routes = Rails.root + 'config/routes.rb'
    destination = File.join(destination_root, "config")
    FileUtils.mkdir_p(destination)
    FileUtils.cp routes, destination
  end
  before { run_generator %w(posts) }
  describe 'config/routes.rb' do
    subject { file('config/routes.rb') }
    it { should contain 'resources :posts' }
  end
end

That first before block is really ugly though! Ammeter should hide that ugliness and I need to think about what the block should look like. Rails with TestUnit does this with setup :copy_routes (https://github.com/rails/rails/blob/master/railties/test/generators/controller_generator_test.rb#L8) but I'd prefer something more general. Maybe

setup_file 'config/routes.rb'

WDYT?

@rafamvc
Copy link
Author

rafamvc commented Jun 14, 2012

I was actually making a pull request, and based the solution on the routes test from devise.

Looking closer, devise actually implements its own copy_routes, and that is what I did.

def copy_routes
  routes = File.expand_path("../../dummy/config/routes.rb", __FILE__)
  destination = File.join(destination_root, "config")

  FileUtils.mkdir_p(destination)
  FileUtils.cp routes, destination
end

describe RailsOauthProvider::Generators::InstallGenerator do
  # Tell the generator where to put its output (what it thinks of as Rails.root)
  destination File.expand_path("../../../tmp", __FILE__)
  before do
    prepare_destination
    copy_routes 
  end

  describe 'no arguments' do
    #Test implementation
  end
end

It is up to you to if you want to leave this as is and be a 1 to 1 representation of the Rails::Generators::TestCase, or to choose to break from the interface and enhance it.

I don't mind doing a pull request with the contents and test of my comment, just let me know what direction you want it implemented.

BTW, thanks for the gem. It looks pretty good.

@alexrothenberg
Copy link
Owner

Yes it would be great if you want to do a pull request.

Let's stick with copy_routes, since this is the first time its come up and maybe its too soon to over-generalize.

Glad you find this useful. I'm looking forward to your fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants