<commit_before>require 'rails_helper'

RSpec.describe "games/show", type: :view do
  before(:each) do
    @game = assign(:game, Game.create!())
  end

  it "renders attributes in <p>" do
    render
  end
end<commit_msg>Add specs for show view on new game<commit_after>require 'rails_helper'
require 'capybara/rspec'

LIVES_LEFT_REGEX   = /\AYou have (\d+) lives left\z/
GUESSED_WORD_REGEX = /\ACurrently guessed word is:(.*)\z/
GUESSES_REGEX      = /\AYou have guessed:(.*)\z/

def find(selector)
  Capybara.string(rendered).find(selector).text.strip
end

def lives_left
  find('#livesleft').match(LIVES_LEFT_REGEX)[1].to_i
end

def guessed_word
  find('#guessed_word').match(GUESSED_WORD_REGEX)[1]
                       .gsub(/ /, '')
                       .chars.map { |character| character unless character == '_' }
end

def guesses
  find('#guesses').match(GUESSES_REGEX)[1]
                  .gsub(/ /, '')
                  .chars
end

def finished
  find('#finishedstate')
end

RSpec.describe "games/show", type: :view do
  before(:each) do
    @game = assign(:game, Game.create!())
  end

  it "renders attributes in <p>" do
    render
  end

  context "with a new game" do
    before { @game = assign(:game, Game.create!()) }

    it "should show 10 lives left" do
      render

      expect(lives_left).to be 10
    end

    it "should have an empty guessed word" do
      render

      expect(guessed_word.compact).to be_empty
    end

    it "should not have any guesses" do
      render

      expect(guesses).to be_empty
    end

    it "should not be finished" do
      render

      expect(finished).to be_empty
    end
  end
end
{'fraction_non_alphanumeric': 0.12021857923497267, 'fraction_numerical': 0.004250151791135397, 'mean_word_length': 2.6622222222222223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1870769', 'n_tokens_mistral': 584, 'n_tokens_neox': 542, 'n_words': 151}