class TestController < AplicationController
#....
private
def some_method
unless @my_variable.nil?
#...
return true
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想some_method
直接在控制器规范中测试:
require 'spec_helper'
describe TestController do
it "test some_method"
phone = Phone.new(...)
controller.assign(:my_variable,phone) #does not work
controller.send(:some_method).should be_true
end
end
Run Code Online (Sandbox Code Playgroud)
如何从控制器规范中设置TestController
实例变量@my_variable
?
我如何添加自定义css文件?以下配置对我不起作用:
# conf.py
html_static_path = ['_static']
html_theme = 'default'
html_theme_options = {
'cssfiles': ['_static/style.css']
}
Run Code Online (Sandbox Code Playgroud)
结果:
C:\temp\test-docs\docs>make html
Running Sphinx v1.2.2
loading pickled environment... not yet created
building [html]: targets for 2 source files that are out of date
updating environment: 2 added, 0 changed, 0 removed
reading sources... [ 50%] help
reading sources... [100%] index
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents...
Theme error:
unsupported theme option 'cssfiles' given
Run Code Online (Sandbox Code Playgroud) 如何用capybara检查页面上的html内容?
page.should have_text('this is <b>bold</b> "text"')
Run Code Online (Sandbox Code Playgroud)
输出:
Failure/Error: page.should have_text('this is <b>bold</b> "text"') expected there to be this is <b>bold</b> \"text\" in "....this is bold \"text\"....."
我有css文件:
<head>
<link rel="stylesheet" type="text/css" href="/assets/application.css" media="screen" />
...
</head>
Run Code Online (Sandbox Code Playgroud)
对于所有浏览器,一切都很好(chrome,ff,ie8,ie10,...),IE9除外.
IE9不会完全加载css.
我已经确认这种方法有效。基本上它从控制器获取电子邮件并更改特定用户的电子邮件。
但是,它实际上从未保存数据。我传递了错误的电子邮件格式,如果我传递正确的电子邮件方法返回 true,则它返回 false,这意味着它分配了一个新电子邮件并称为安全。
# Allows user to change email address
def change_email(newmail)
address = EmailVeracity::Address.new(newmail)
if address.valid?
self.email = newmail
self.save
return true
else
return false
end
end
Run Code Online (Sandbox Code Playgroud)
我首先检查了日志是否有任何提示,但我得到的只是:
Started POST "/members/editmail" for 127.0.0.1 at 2013-04-25 17:33:44 +0200
Processing by MembersController#editmail as HTML
Parameters: {"authenticity_token"=>"*****=", "mail"=>"*****@gmail.com"}
?[1m?[35mUser Load (1.0ms)?[0m SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
?[1m?[36mCharacter Load (0.0ms)?[0m ?[1mSELECT `characters`.* FROM `characters` WHERE `characters`.`user_id` = 1?[0m
?[1m?[35m (0.0ms)?[0m BEGIN
?[1m?[36mUser Exists (0.0ms)?[0m ?[1mSELECT 1 FROM …
Run Code Online (Sandbox Code Playgroud) 我有Exception encountered: #<SystemExit: exit>
错误,当尝试通过spork运行黄瓜.
功能/支持/ env.rb:
require 'rubygems'
require 'spork'
require 'cucumber/rails'
require 'pickle/world'
require "capybara/poltergeist"
Spork.prefork do
Capybara.javascript_driver = :poltergeist
end
Spork.each_run do
ActionController::Base.allow_rescue = false
begin
DatabaseCleaner[:mongoid].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
DatabaseCleaner[:mongoid].clean
Cucumber::Rails::Database.javascript_strategy = :truncation
end
Run Code Online (Sandbox Code Playgroud)
没有spork运行:
vagrant@lucid32:/vagrant$ bundle exec cucumber
WARNING: No DRb server is running. Running features locally:
Rack::File headers parameter replaces cache_control after …
Run Code Online (Sandbox Code Playgroud) 我正在使用sphinx 1.2.2和readthedocs.ru以及默认主题(sphinx_rtd_theme).
我怎么可以延长layout.html
?以下代码不起作用:
#_templates/layout.html
{% extends "!layout.html" %}
{% block extrahead %}
{{ super() }}
<link href='http://fonts.googleapis.com/css?family=PT+Mono&subset=latin,cyrillic' rel='stylesheet' type='text/css'>
{% endblock %}
Run Code Online (Sandbox Code Playgroud) #spec
let(:price) { create :price,:some_trait,:my_trait }
#factory
FactoryGirl.define do
factory :price, class: 'Prices::Price' do
...
after(:build) do |p,e|
# How I can get the traits passed to the create method?
# => [:some_trait,:my_trait]
if called_traits_does_not_include(:my_trait) # fake code
build :price_cost,:order_from, price:p
end
end
...
end
end
Run Code Online (Sandbox Code Playgroud)
我如何获得create
在工厂after(:build)
回调中传递的特征?
是否可以在Struct
实例中创建动态属性?
class Person < Struct.new(:name)
end
p = Person.new("Bilbo")
p[:surname] = "Jenkins" # does not work
Run Code Online (Sandbox Code Playgroud) 我想找到一个使用os.listdir()函数(或任何其他方法)访问目录的函数,并返回该目录中的所有文件名,但将非ASCII字符转换为其unicode格式.例如,如果我有文件Hello Worl?.py
,我希望函数返回Hello Worl\u042a.py
或等效.任何帮助表示赞赏.