Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cabloo/837454f067cf1439da716b2ff0167dcc to your computer and use it in GitHub Desktop.
Save cabloo/837454f067cf1439da716b2ff0167dcc to your computer and use it in GitHub Desktop.
describe "#generate" do
let(:subject) { described_class.generate(name, player) }
let(:player) { Player.create(user_name: "Ronald McDonald", display_name: "Mac") }
let(:name) { "Ronnie the Rat" }
context "with defaults" do
it { expect(subject.name).to eq name }
end
context "with nil player" do
let(:player) { nil }
it { expect(subject).to eq nil }
end
context "with other existing character" do
before { described_class.generate(existing_name, existing_player) }
let(:existing_player) { player }
context "having a different name" do
let(:existing_name) { "something else" }
it { expect(subject).to be_present }
end
context "having the same name" do
let(:existing_name) { name }
it { expect { subject }.to raise_error "Character name already exists" }
context "under a different player" do
let(:existing_player) { Player.create(user_name: "existing", display_name: "existing") }
it { expect(subject).to be_present }
end
end
end
context "with name containing invalid characters" do
let(:name) { "#@!" }
it { expect { subject }.to raise_error "Character name must be alphanumeric or spaces" }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment