Discussion Forums
- Topic List
- Most Recent Posts
- Sign In for more options
Hi,
I'm new to BDD and wonder if which one below is better:
Approach 1 - use member variable Given /my group has "([\"]*)" worker$/ do |worker_login| @worker = Factory.create(:worker,:login => worker_login, :worker_groups => @leader.worker_groups) end
When /I navigate to "([\"]*)" page$/ do |worker_login| visit worker_path(@worker) end
Approach 2 Given /my group has "([\"]*)" worker$/ do |worker_login| Factory.create(:worker, :login => worker_login, :worker_groups => @leader.worker_groups) end
When /I navigate to "([\"]*)" page$/ do |worker_login| worker = Worker.find_by_login(worker_login) visit worker_path(worker) end
Thanks for your help! Lam
I guess the answer is it depends. The first approach keeps your features cleaner and may be a little bit faster (less db queries). The second is more explicit and helps to avoid collisions that are hard to debug (when you accidentally overwrite the instance variable in some step). I personally use the first approach most of the time. But sometimes I need the feature to be explicit and I use the second one.
