我有一类称为Imprintables嵌套资源Styles,Brands,Colors,和Sizes.我目前在我的路线文件中有这个:
resources :imprintables do
resources :styles, :brands, :colors
resources :sizes do
collection do
post 'update_size_order'
end
end
end
Run Code Online (Sandbox Code Playgroud)
哪个产生这样的路线:
/imprintables/:imprintable_id/brands
/imprintables/:imprintable_id/colors
/imprintables/:imprintable_id/styles
/imprintables/:impritnable_id/sizes
Run Code Online (Sandbox Code Playgroud)
我不希望所有嵌套资源都绑定到1个特定的imprintable.我希望我的路线看起来像:
/imprintables/brands
/imprintables/styles
/imprintables/colors
/imprintables/sizes
Run Code Online (Sandbox Code Playgroud)
...等等.
什么是最好的方式来解决这个问题?
敬礼!
我正在尝试用Rspec测试一个控制器方法,如下所示:
def email_customer
@quote = Quote.find(params[:quote_id])
hash = {
quote: @quote,
body: params[:email_body],
subject: params[:email_subject]
}
QuoteMailer.email_customer(hash).deliver
redirect_to edit_quote_path params[:quote_id]
end
Run Code Online (Sandbox Code Playgroud)
相应的规范如下所示:
describe 'POST email_customer' do
let!(:quote) { create(:valid_quote) }
it 'assigns the quote and sends the customer an email' do
post :email_customer, quote_id: quote.id
expect(assigns(:quote)).to eq(quote)
expect(QuoteMailer).to receive(:email_customer).with(an_instance_of(Hash)).and_return( double('QuoteMailer', deliver: true))
end
end
Run Code Online (Sandbox Code Playgroud)
当测试运行时,我收到此消息:
Failure/Error: expect(QuoteMailer).to receive(:email_customer).with(an_instance_of(Hash)).and_return( double('QuoteMailer', deliver: true))
(<QuoteMailer (class)>).email_customer(an instance of Hash)
expected: 1 time with arguments: (#<RSpec::Matchers::AliasedMatcher:0x0000000c2b1e28 @description_block=#<Proc:0x00000009816268@/home/david/.rvm/gems/ruby-2.1.1/gems/rspec-expectations-3.0.0.beta2/lib/rspec/matchers.rb:231 (lambda)>, @base_matcher=#<RSpec::Matchers::BuiltIn::BeAnInstanceOf:0x0000000c2b1e50 @expected=Hash>>)
received: 0 times …Run Code Online (Sandbox Code Playgroud) 现在我们正在努力采用Cucumber在我们的Java8/Spring应用程序上运行功能测试.我们希望我们的步骤定义文件尽可能保持DRY,因此计划在不同的功能文件中使用相同的步骤定义.由于我们使用硒WebDriver来驱动我们的测试,我们需要在步骤定义之间共享相同的驱动程序.
To demonstrate why having multiple drivers is an issue for us, imagine a feature file that defines two steps: one to navigate to a page, and another to assert that a line appears on that page. If both steps happen to be defined in separate files, the first step definition will use its driver to navigate to the page. By the time the second step definition runs the assertion against its driver it hasn't navigated to the …