require 'test_helper' module LucidTDL describe Parser do def parse(input) parser = Parser.new parser.parse(input) end describe "Feature Element" do it "parses feature description without narrative" do feature = parse("Feature: Test Feature") feature.must_be_kind_of AST::Feature feature.name.must_equal "Test Feature" end it "parses feature description with narrative" do feature = parse("Feature: Test Feature\n As a... \n I want... \n So that...\n") feature.must_be_kind_of AST::Feature feature.name.must_equal "Test Feature" end it "parses a feature with tags" do feature = parse(""" @wip @selenium Feature: Test Feature """) feature.name.must_equal "Test Feature" feature.tags.first.name.must_equal "wip" feature.tags.last.name.must_equal "selenium" end it "parses a feature with tags, without prior newline" do feature = parse("@wip\nFeature: Test Feature") feature.name.must_equal "Test Feature" feature.tags.first.name.must_equal "wip" end end describe "Ability Element" do it "parses ability description without narrative" do feature = parse("Ability: Test Ability") feature.must_be_kind_of AST::Feature feature.name.must_equal "Test Ability" end it "parses ability description with narrative" do feature = parse("Ability: Test Ability\n As a... \n I want... \n So that...\n") feature.must_be_kind_of AST::Feature feature.name.must_equal "Test Ability" end end describe "Responsility Element" do it "parses responsibility description without narrative" do feature = parse("Responsibility: Test Responsibility") feature.must_be_kind_of AST::Feature feature.name.must_equal "Test Responsibility" end it "parses responsibility description with narrative" do feature = parse("Responsibility: Test Responsibility\n As a... \n I want... \n So that...\n") feature.must_be_kind_of AST::Feature feature.name.must_equal "Test Responsibility" end end describe "Backgrounds and Context" do it "parses a background" do feature = parse(""" Feature: Test Feature Background: Given a situation applies And a context is operative """) feature.name.must_equal "Test Feature" feature.background.must_be_kind_of AST::Background steps = feature.background.steps given_step = steps.first and_step = steps.last given_step.keyword.must_equal "Given" given_step.name.must_equal "a situation applies" and_step.keyword.must_equal "And" and_step.name.must_equal "a context is operative" end it "parses a context" do feature = parse(""" Feature: Test Feature Context: Given a situation applies And a context is operative """) feature.name.must_equal "Test Feature" feature.background.must_be_kind_of AST::Background steps = feature.background.steps given_step = steps.first and_step = steps.last given_step.keyword.must_equal "Given" given_step.name.must_equal "a situation applies" and_step.keyword.must_equal "And" and_step.name.must_equal "a context is operative" end end describe "Scenarios and Tests" do it "parses a feature with scenarios and tests" do feature = parse(""" Feature: Test Feature Scenario: A Scenario Given some context When some action Then some observable Test: A Test Given some context When some action And some other action Then some observable But not some other observable """) scenarios = feature.scenarios first_scenario = scenarios.first last_scenario = scenarios.last first_scenario.name.must_equal "A Scenario" first_scenario.steps.first.name.must_equal "some context" first_scenario.steps.last.name.must_equal "some observable" last_scenario.name.must_equal "A Test" last_scenario.steps.first.name.must_equal "some context" last_scenario.steps.last.name.must_equal "not some other observable" end it "parses a feature with generic steps" do feature = parse(""" Feature: Test Feature Scenario: A Scenario * some context * some action """) scenarios = feature.scenarios first_scenario = scenarios.first first_scenario.name.must_equal "A Scenario" first_scenario.steps.first.name.must_equal "some context" first_scenario.steps.last.name.must_equal "some action" end it "parses a scenario with tags" do feature = parse(""" Feature: Test Feature @critical @regression @smoke Scenario: A Scenario Given some context When some action Then some observable """) scenarios = feature.scenarios first_scenario = scenarios.first first_scenario.tags[0].name.must_equal "critical" first_scenario.tags[1].name.must_equal "regression" first_scenario.tags[2].name.must_equal "smoke" end end end end