已解决:原作者在某一点上用f @#$ ing类变量进行了记忆。
@@roles ||= Role.all
家长们,与孩子讨论ruby中的类变量。在别人做之前。
编辑:为用户创建步骤添加了方案和代码。
我正在努力测试旧的遗留代码库,在使用黄瓜时遇到问题。
系统中有“患者”,“网站”和“管理员”用户。有些测试需要您与患者一起登录,其他测试需要有站点,管理员等。当我只运行带有签名患者的功能时,它们都可以正常工作。当我只使用已登录的站点用户运行功能时,它们都可以正常工作。当我只运行带有签名管理员的功能时,它们都可以正常工作。当我尝试使用多种类型的用户运行混合功能时,第二种和第三种用户的功能不起作用。
我发现的一个线索是它似乎将所有用户视为在测试运行中首先登录的用户类型。
以下是网站用户的示例测试
Background:
Given that I am an "site" user
Scenario: Patients compliance report page
When I have patient "Joel" with "4" missed days in diary
And I go to compliance report page
Then I should see "Patient Compliance Report"
And I should see columns
| Site #/Investigator |
| Patient |
| Registration Date |
| Compliance % |
后台步骤调用以下方法:
def create_and_login_as_role(role)
role_sym = :"#{role}_user"
diary = FactoryGirl.create :diary
study = FactoryGirl.create :study
site = FactoryGirl.create :site, study: study
user = FactoryGirl.create role_sym, diary: diary, organization: site
login user.username, DEFAULT_PASSWORD
end
def login(username, password)
visit destroy_user_session_path # kills any session, then defaults to login
fill_in 'user[username]', with: username
fill_in 'user[password]', with: password
click_on "Sign in"
end
这是第二个场景
Background:
Given there are two countries
And there is a region
Given that I am an "admin" user
#I have to create 'ted' second because of the stupid hold-on-to-first-user-type bug
And there is a site user "ted"
Scenario: Creating a site user
And I visit the "sites" page
And I click "New Site"
And I select the first study from the list
And I select "USA" from "Country"
And I select "North America" from "Region"
And I fill in "Site Number" with "234"
And I fill in "Site Name" with "SiteySiteful"
And I select "Active" from "Status"
And I select "ted" from "Investigator"
And I select "ted" from "Primary Contact"
And I fill in "password" with "password"
And I click "Create Site"
Then I should see "Site was successfully created"
在这种情况下,该错误的第二个表现形式。如果我首先创建了站点用户(它只是对工厂的调用),则它以站点用户身份登录admin用户。
以下是用户的工厂:
FactoryGirl.define do
factory :user do |u|
sequence(:email) {|n| "example#{n}@verdacom.com" }
sequence(:username) {|n| "user#{n}"}
password "password"
tmp_password "password"
country_id 1
user_state { FactoryGirl.create(:user_state) }
password_confirmation {|u| u.password}
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
work_phone "0123456789"
mobile_phone "0123456789"
timezone "Etc/UTC"
diary_creation true
diary { FactoryGirl.create(:diary) }
end
factory :admin_user, :parent => :user, :class => User do |s|
sequence(:email) {|n| "admin#{n}@verdacom.com" }
sequence(:username) {|n| "admin#{n}"}
force_update_password false
roles { [FactoryGirl.create(:admin_role)] }
end
factory :diary_author, :parent => :user, :class => User do |s|
diary nil
end
factory :subject_user, :parent => :user, :class => User do |s|
roles {[FactoryGirl.create(:subject_role)]}
diary {FactoryGirl.create(:diary_with_registration_entry)}
# s.organization { |user| user.association :site }
end
factory :site_user, :parent => :user, :class => User do
sequence(:email) {|n| "site#{n}@verdacom.com" }
sequence(:username) {|n| "site#{n}"}
force_update_password false
roles { [FactoryGirl.create(:site_role)] }
# organization { |user| user.association :site }
end
end
这是我的宝石文件;值得注意的是rails 3.1.5,devise,mysql2,activeadmin自定义fork(不是我的选择),cancan,guard,cucumber_rails和database_cleaner
source 'http://rubygems.org'
gem 'rails', '3.1.5'
gem 'mysql2'
gem 'activeadmin', :path => "vendor/gems/activeadmin-0.3.4", :git => "https://github.com/alexey/active_admin.git", :branch => "0.3.4-stable" #
gem "haml"
gem "rake", ">= 0.9.2"
gem "meta_search", '>= 1.1.0.pre'
gem 'cancan'
gem 'twiliolib'
gem 'paper_trail'
gem 'jquery-rails'
gem 'capistrano'
gem "capistrano-ext"
gem 'seed-fu', '~> 2.1.0'
gem "timezone"
gem "twilio-ruby"
gem "yettings"
gem "zipruby"
gem "whenever", :require => false
gem "newrelic_rpm"
gem "rabl"
gem 'andand'
gem "execjs"
gem "therubyracer"
gem "hoptoad_notifier", '2.3.11'
gem "faker" # need in development and production/staging also
gem 'sass-rails', '~> 3.1.4'
group :assets do
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
group :test do
gem 'turn', '< 0.8.3'
gem 'cucumber-rails', require: false
gem 'factory_girl_rails'
gem 'launchy'
gem "timecop" # for time travelling to test "entries" timeframe
gem "rack-test"
gem "prawn" # for pdf test report generation
gem "webrat" # simulte http interaction with remote service
end
group :test, :development do
gem "rspec-rails", "~> 2.6"
gem "shoulda"
gem "simplecov" # rcov not supported in ruby 1.9
gem 'capybara-webkit' # for headless testing
gem 'database_cleaner'
gem 'debugger'
gem 'rb-fsevent'
gem 'spork', '~> 1.0rc'
gem 'guard'
gem 'guard-spork'
gem 'guard-rspec'
gem 'guard-cucumber'
gem 'single_test'
end
group :development do
gem 'rails-footnotes', '>= 3.7.5.rc4'
gem "rails-erd"
gem 'pry'
gem 'pry-rails'
gem 'redcarpet'
gem 'quiet_assets'
end
platforms :ruby do
gem 'rb-readline'
end
这是我对于cucumber的database_cleaner设置,这正是他们的github自述文件中的内容:
begin
require 'database_cleaner'
require 'database_cleaner/cucumber'
DatabaseCleaner.strategy = :truncation
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end
Before do
DatabaseCleaner.start
end
After do |scenario|
DatabaseCleaner.clean
end
任何帮助将不胜感激。请询问任何可能相关的文件。
答案 0 :(得分:0)
已解决:原作者在某一点上用f @#$ ing类变量进行了记忆。
@@roles ||= Role.all
当然,数据库清理程序不会重置类变量,因为f @#$在ruby中使用类变量?
家长们,与孩子讨论ruby中的类变量。在别人做之前。