vlad pollutes global namespace #21

Closed
rwestgeest opened this Issue May 9, 2012 · 6 comments

Comments

Projects
None yet
2 participants

Hi,

First of all - i love vlad. Much simpler than capistrano. Thanks!

I have this issu:

I have put vlad, vlad git and factory_girl in my Gemfile like this:

group :development do
  #...
  gem "factory_girl_rails"
  gem "vlad"
  gem "vlad-git"
  #...
end

and because i have an account with a role, in a factory.rb i have:

  FactoryGirl.define do
    factory :maintainer_account, :class => Account do
      sequence( :email ) { |n| "account_#{n}@mail.com" }
      role Account::Maintainer
    end
  end

Now when i run rake i get:

rake aborted!
host required

Which comes from the role method in RakeRemoteTask.

I first thought that i may be a factory_girl problem but, it is odd that the role method is available in the global namespace, isn't it?

What do you think ?

Oh eh, should i have posted this your rake-remote_task project ?

Owner

zenspider commented May 9, 2012

Shouldn't you be including factory girl only for test?

Thanks that solves it

i wonder however

test and development go hand in hand

and

putting rspec test group makes the 'spec:*' rake task not show up

so

now i end up with rspec in my :development group and rspec requirements in the :test group.

but that has nothing to do with vlad

thanks again

rwestgeest closed this May 9, 2012

Id like to reopen this one:

Vlad actually polutes the global namespace with 'set'. I think it is a bad idea and it gives problems that I don't know how to solve elegantly without violating vlad's design principles.

To narrow the problem down to its essence: Given i have a simple rakefile:

begin
  require "vlad"
  Vlad.load(:scm => "git")
rescue LoadError => e
  puts "cant load vlad check rakefile #{e.message}"
  # do nothing
end

task :default => :tests

desc "runs tests"
task :tests do
  Dir['test/*_test.rb'].each do |f|
    require_relative f
  end
end

and an empty config/deploy.rb and a test file named test/global_name_space_test.rb:

require 'test/unit'

class GlobalNameSpace < Test::Unit::TestCase
  def test_is_poluted
    assert_instance_of Vlad::Git , source
  end
end

when i run rake i see

Run options: 
# Running tests:
.
Finished tests in 0.000979s, 1021.5590 tests/s, 1021.5590 assertions/s.

Now, in a somewhat biggish rails application I get failures that did work before including vlad. All of the failures are arround using the word 'source'. I just migrated it from Rails 1.2.3, therefore It works with test/unit. As I like vlads simplicity, I decided to replace capistrano. Sadly it gave me unexpected errors.

What bothers me is that although in my first submission of this issue, I agreed on not using FactoryGirl outside test. But rake is used for running tests and deploy tasks (and other project related tasks) and therefore code in rake is always used in conjunction with test task like above. Poluting the Object namespace in the way vlad-git / vlad does through using set in rake_remote-task inevitably leads to problems.

Is there any way to elegantly work around this or is there a way to change 'set''s design so that it keeps the settings locally or only available to the context of the deploy file ?

Any ideas ?

rwestgeest reopened this Oct 17, 2013

I have worked around this by making a small shell script containing

#!/bin/sh
rake -f Vladfile $@

and a Vladfile with

begin               
    require "vlad"         
    Vlad.load(:scm => "git")
rescue LoadError => e
    puts "cant load vlad check Vladfile #{e.message}"
    # do nothing           
end

It feels a bit yucky to work around an Object namespace pollution this way, but for now it works.

Still interested in other ideas.

oelmekki referenced this issue in agile-france/propile Nov 14, 2013

Merged

FIX rake's vlad interference #24

Owner

zenspider commented Apr 1, 2014

I'm not going to change this. This is just how vlad works.

zenspider closed this Apr 1, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment