开发者

How do you handle adding something like Devise authentication in BDD stories?

If you have a set of BD开发者_运维百科D scenarios like:

  • User should be able to register
  • User should be able to login
  • User should be able to reset password

etc., normally you write the first scenario, then write the code to make it pass, and then refactor.

But if you use something like Devise, which, once correctly installed and configured, gives you all these features at once, what is the best practice for that? Because, if you write the first test and configure Devise so that the test passes, the other tests that you write should automatically pass without having failed before. Or is having the tests fail first not strictly necessary in a BDD workflow, and I should just be happy that the tests pass?


With BDD, you should focus on the value you're providing to your users or stakeholders. Logging in isn't really valuable, so I'd give them something to log in for first.

Then the scenarios become easy, either:

Given Fred is logged in
When Fred buys a book...

or

Given Fred is on his home page
When Fred buys a book...

Logging in has no value, and I apologise for being one of the people who's used that as a BDD example in previous years. Don't log in unless you need to, and certainly don't code it first.

I'd write scenarios for my 3rd party apps only if I didn't trust them, at which point, yes, they might fail. Probably better to simply use them in your own valuable scenarios.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜