← Back to Upcase

Marking Todos Incomplete

This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/marking-todos-incomplete

Hi, so in the Todo unit test, in the repeated line:

expect(todo).not_to be_completed

What exactly does the “be_completed” derive from? Seems a little cryptic.

RSpec provides dynamic predicate matchers. It’s roughly equivalent to writing:

expect(todo.completed?).to eq(false)

It’s definitely one of the more confusing aspects of RSpec.

@joshuaclayton I’m a little bit uncomfortable with using POST and DELETE to mark todos as completed and incompleted respectively mainly because the POST verb was not meant to be idempotent and it ends up being, in this approach. On the other way, I like how all controllers has just one responsability, even the completion controller. Is this one of that cases where we are consciously breaking a rule in favor of a better overall solution?

I am getting:

User marks todo incomplete successfully
Failure/Error: click_on "Mark complete"
Ambiguous match, found 2 elements matching link or button “Mark complete”

Database_cleaner appears to not be running properly between feature tests, and I am getting two LI’s due to user_completes_todo then the later user_marks_todo_incomplete

I confirmed this is the case, by removing the user_completes_todo_spec and the user_creates_todo_spec which runs before the user_marks_todo_incomplete, in that case the spec does not find multiple todo LI’s.

I am on rails 4.2 and also using postgres.

Changing my support/database_cleaner.rb file to this fixed the issue:

RSpec.configure do |config|

  config.before(:suite) do

  config.before(:each) do |example|
    DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction

  config.after(:each) do
1 Like

Thanks! Was running into the same bump today.

Thanks for the solution! I was facing the same issue.