我有以下规格:
context "no firstname present" do
let(:contact) { build :contact, firstname: 'Mickey', lastname: '', companyname: '' }
it "should be valid" do
should be_valid # Does not work
contact.should be_valid # Works
end
end
Run Code Online (Sandbox Code Playgroud)
为什么should be_valid失败,但contact.should be_valid通过?在it街区内,无论如何should be_valid应该访问contact?!谢谢你的澄清.
我尝试进行符合最佳实践的RSpec测试,我知道在测试实例方法时,可以做到
describe "#my_instance_method" do ... end
Run Code Online (Sandbox Code Playgroud)
但是类方法怎么样?我应该self.在描述字符串中添加一个吗?
describe "#self.my_class_method" do ... end
Run Code Online (Sandbox Code Playgroud)
感谢您的意见!
可能重复:
每两个表行的nth-child
我正在努力进入CSS3 nth-child选择器,但似乎我现在无法让它工作.
我想要做的是将表格中的前2行设为白色,然后将2行设置为灰色,然后再将2列设为白色,依此类推.我如何只使用CSS?
非常感谢!
我们经常在应用程序中偶然发现未翻译的模型属性.它们通常是因为某个属性被重命名或类似的东西而来.
当Model.human_attribute_name :field找不到翻译时让I18n引发错误会非常有帮助.有没有办法实现这个目标?
更新:
似乎还有其他一些问题.这是我的I18n设置:
I18n.enforce_available_locales = false
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
config.i18n.default_locale = 'de-CH'
config.i18n.available_locales = ['de', 'de-CH', 'en']
config.i18n.locale = 'de-CH'
config.i18n.fallbacks = {'de-CH' => 'de', 'en-GB' => 'en'}
Run Code Online (Sandbox Code Playgroud)
我无法设置,fallbacks = false因为我想要缺少de-CH优雅委托的翻译de,这通常似乎工作正常.但对于我的状态机属性human_to_state方法,它似乎不起作用.这是导致问题的视图代码:
= f.input :state_event, collection: f.object.state_transitions,
label_method: :human_to_name # This causes the problem!
Run Code Online (Sandbox Code Playgroud)
这在视图中打印为"状态事件",当我添加以下I18n键时,它成功转换为"状态":
de:mongoid:attributes:activity:state_event:Status
所以真的是一个漏译,但确实的I18n不以任何方式抱怨.我还尝试使用自定义异常处理程序捕获异常,但似乎没有引发:
I18n.exception_handler = lambda do |exception, locale, key, options|
binding.pry # This is never reached! …Run Code Online (Sandbox Code Playgroud) Guard-RSpec 在自述文件中提到可以通过指定 cusom 使用 spring 运行规范cmd:
guard :rspec, cmd: 'spring rspec' do
# ...
end
Run Code Online (Sandbox Code Playgroud)
这曾经工作得很好,直到我做了一个spring binstub --all改变了我bin/spring的...
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'spring' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('spring', 'spring')
Run Code Online (Sandbox Code Playgroud)
...到...
#!/usr/bin/env ruby
# This file loads spring without using …Run Code Online (Sandbox Code Playgroud) 有没有快速的方法来在Ruby中对"章节数"进行排序?
1.1.1
1.1.2
1.2.1
1.3.1
1.3.2
1.3.3
10.42.64
etc.?
Run Code Online (Sandbox Code Playgroud)
我是否必须写一个调查员或类似的东西?
我有以下行动:
def create
binding.pry
@finding.save
respond_with @project, @finding
end
Run Code Online (Sandbox Code Playgroud)
运行以下测试时...
it 'balances the consecutive numbers', focus: true do
expect {
post :create, params: {...}
}.to change { Finding.count }.from(0).to 1
end
Run Code Online (Sandbox Code Playgroud)
...我首先binding.pry显示控制台(证明该#create操作实际已执行),然后规范通过:
Finished in 4.24 seconds (files took 5.31 seconds to load)
1 example, 0 failures
Run Code Online (Sandbox Code Playgroud)
现在当我添加一个expect(controller).to receive(:create)...
it 'balances the consecutive numbers', focus: true do
expect(controller).to receive(:create) # This is new!
expect {
post :create, params: {...}}
}.to change { Finding.count }.from(0).to 1 …Run Code Online (Sandbox Code Playgroud) 我正在尝试水平对齐HTML定义列表,因此术语在左侧,定义在右侧.
术语和定义都可以很长,因此它们可以比可用宽度更宽并且将包裹.
使用我的CSS,我对包装的定义没有问题,因此高于相应的术语.但是在极少数情况下,当术语包装并且高于相应的定义时,我没有得到以下定义来正确清除.
您可以在我的jsFiddle中看到这一点,其中定义"555"未与术语"555"正确对齐.
http://jsfiddle.net/jmuheim/kjf8f/
任何有关如何解决这个问题的帮助真的很感激.要求:
<dd>标签使用固定宽度.虽然所有WAI-ARIA属性都有一个aria-前缀(如aria-labelledby或aria-required),但WAI-ARIA属性role却没有(我猜它aria-role会无效).这是什么原因?
我已经在Google上进行了搜索,但是虽然他们解释了很多关于如何使用和实现WAI-ARIA的内容,但他们似乎并没有谈论这个具体事实.
http://www.w3.org/TR/wai-aria-primer/ http://www.w3.org/TR/wai-aria/host_languages
我使用 Pandoc 为我的网站创建内容。
例如,我的页面上有以下内容:
# About me
Some text.
## My hobbies
### Hiking
Some text about hiking.
### Dancing
Some text about dancing.
### Other
Some text about other.
## Why I love Pandoc
Some more text.
Run Code Online (Sandbox Code Playgroud)
Pandoc 为我解析这个并输出漂亮的 HTML。
但我想进一步对此 HTML 进行后处理,例如我希望爱好部分变成手风琴。
为此,我希望它位于自己的容器中,例如<div class="accordion">. 这有可能吗?
更新
通过将一个类附加到特定标题,我可以实现接近我需要的东西:
## My hobbies {.accordion}
...
Run Code Online (Sandbox Code Playgroud)
现在我可以使用 CSS 来定位所有内容(代码未测试):
h2.accordion ~ *:not(h1, h2) {
color: red;
}
Run Code Online (Sandbox Code Playgroud)
这假设同一(或更高)级别上的下一个标题之前的所有内容都属于轮播。
这可能会有帮助。我不知道它是否符合我的所有要求,但这是一个开始。