Stamm
@Stamm

FactoryGirl: название функции в хелпере совпадает с названием столбца?

Есть FactoryGirl и rspec.

У модели Post есть столбец title

Также есть функция title в ApplicationHelper. Эта функция мне нужна внутри других тестов.



module ApplicationHelper<br>
  # Return a title on a per-page basis.<br>
  def title<br>
    base_title = "Blog"<br>
    if @title.nil?<br>
      base_title<br>
    else<br>
      "#{base_title} | #{@title}"<br>
    end<br>
  end<br>
end<br>




spec/factories.rb



FactoryGirl.define do<br>
  factory :post do<br>
    title  "Title #1"<br>
  end<br>
end<br>




spec/support/utilities.rb



include ApplicationHelper<br>



spec/requests/articles_pages_spec.rb



require 'spec_helper'<br><br>
describe "Articles page" do<br>
  subject { page }<br><br>
  describe "index page" do<br>
    let(:post) { FactoryGirl.create(:post) }<br>
    before { visit root_path }<br><br>
    it { should have_selector('h2 a', text: post.title) }<br>
  end<br><br>
end<br>




Запускаем тесты и получаем ошибку



rspec spec/requests/articles_pages_spec.rb



/Users/stamm/Sites/ruby/blog-ror/app/helpers/application_helper.rb:3:in `title': wrong number of arguments (1 for 0) (ArgumentError)
	from /Users/stamm/Sites/ruby/blog-ror/spec/factories.rb:10:in `block (2 levels) in &lt;top (required)&gt;'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:18:in `instance_eval'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:18:in `factory'
	from /Users/stamm/Sites/ruby/blog-ror/spec/factories.rb:9:in `block in &lt;top (required)&gt;'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:49:in `instance_eval'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:49:in `run'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/syntax/default.rb:7:in `define'
	from /Users/stamm/Sites/ruby/blog-ror/spec/factories.rb:1:in `&lt;top (required)&gt;'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `block in load'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:245:in `load'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:16:in `block in find_definitions'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:15:in `each'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/find_definitions.rb:15:in `find_definitions'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/factory_girl-4.1.0/lib/factory_girl/reload.rb:6:in `reload'
	from /Users/stamm/Sites/ruby/blog-ror/spec/spec_helper.rb:50:in `block in &lt;top (required)&gt;'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/spork-0.9.2/lib/spork.rb:37:in `each_run'
	from /Users/stamm/Sites/ruby/blog-ror/spec/spec_helper.rb:48:in `&lt;top (required)&gt;'
	from /Users/stamm/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
	from /Users/stamm/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
	from /Users/stamm/Sites/ruby/blog-ror/spec/requests/articles_pages_spec.rb:1:in `&lt;top (required)&gt;'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `block in load_spec_files'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `map'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/configuration.rb:780:in `load_spec_files'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/command_line.rb:22:in `run'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:66:in `rescue in run'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:62:in `run'
	from /Users/stamm/.rvm/gems/ruby-1.9.2-p320/gems/rspec-core-2.11.1/lib/rspec/core/runner.rb:8:in `block in autorun'




Как сделать так, чтобы работало?



Пробовал так:



FactoryGirl.define do<br>
  factory :post do |u|<br>
    u.title  "Title #1"<br>
  end<br>
end<br>




Та же ошибка
  • Вопрос задан
  • 2922 просмотра
Пригласить эксперта
Ответы на вопрос 2
ataraev
@ataraev
Ruby, Go
Самое простое решение перименовать helper, это точно поможет
Ответ написан
sl_bug
@sl_bug
не использовать такую конструкцию

spec/support/utilities.rb

include ApplicationHelper
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы