def test_parsing_files_with_proper_header_returns_parsed_scenario():
    
    mocker = Mocker()
    
    settings = Settings()
    files = ["some path"]
    
    story_text = """As a someone
I want to do something
So that I'm happy"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)
    
        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 1
        assert fixture.stories[0].as_a == "someone"
        assert fixture.stories[0].i_want_to == "do something"
        assert fixture.stories[0].so_that == "I'm happy"
Beispiel #2
0
def test_parse_block_lines():
    parser = FileParser(None, None, None)

    line_index = 5
    line = "And I see table as:"
    scenario_lines = [
        'Line 1', 'Line 2', 'Line 3', 'Scenario bla', 'Given',
        '    And I see table as:', '        | Name | Age | Sex  |',
        '        | Paul | 28  | Male |', '        | John | 30  | Male |'
    ]
    offset, rows, parsed_rows = parser.parse_rows(line_index, line,
                                                  scenario_lines)

    assert offset == 3
    assert rows == [
        '        | Name | Age | Sex  |', '        | Paul | 28  | Male |',
        '        | John | 30  | Male |'
    ]
    assert parsed_rows == [{
        'Name': 'Paul',
        'Age': '28',
        'Sex': 'Male'
    }, {
        'Name': 'John',
        'Age': '30',
        'Sex': 'Male'
    }]
def test_parsing_files_with_empty_content_returns_invalid_files_list():
    
    mocker = Mocker()
    
    settings = Settings()
    files = ["some path"]

    story_text = ""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("no_header_failure")
    mocker.result("No header found")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)
    
        fixture = parser.get_stories(settings=settings)
        assert len(fixture.no_story_header) == 1
        file_path = fixture.no_story_header[0]
        assert file_path == "some path"
Beispiel #4
0
def test_parse_scenario_line():

    mocker = Mocker()

    story = Story(as_a="Someone",
                  i_want_to="Do Something",
                  so_that="I'm Happy",
                  identity="some file")

    settings_mock = mocker.mock()
    settings_mock.scenarios_to_run
    mocker.result([])

    language_mock = mocker.mock()
    language_mock.get("scenario")
    mocker.result("Scenario")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        scenario = parser.parse_scenario_line(story,
                                              "Scenario 1 - Doing something",
                                              settings_mock)

        assert scenario is not None
        assert scenario.index == "1", "Expected 1 actual %s" % scenario.index
        assert scenario.title == "Doing something"
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    class DoSomethingAction(ActionBase):
        regex = r'I do something$'
        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction(ActionBase):
        regex = r'I do something else$'
        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction(ActionBase):
        regex = r'I do yet another thing$'
        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    settings.tests_dirs = [abspath(dirname(__file__))]
    settings.file_pattern = "some_test.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert_no_invalid_stories(fixture)

    assert len(fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
    assert len(fixture.stories[0].scenarios) == 2
    assert "#some custom comment" in fixture.stories[0].scenarios[1].whens[0].description
Beispiel #6
0
def test_parsing_files_with_empty_content_returns_invalid_files_list():

    mocker = Mocker()

    settings = Settings()
    files = ["some path"]

    story_text = ""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("no_header_failure")
    mocker.result("No header found")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.no_story_header) == 1
        file_path = fixture.no_story_header[0]
        assert file_path == "some path"
def test_parsing_folder_with_no_stories_returns_empty_list():
    settings = Settings()
    settings.tests_dirs = [abspath(join(dirname(__file__), "no_stories_folder"))]
    parser = FileParser()

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 0
Beispiel #8
0
def test_parsing_files_with_proper_header_returns_parsed_scenario():

    mocker = Mocker()

    settings = Settings()
    files = ["some path"]

    story_text = """As a someone
I want to do something
So that I'm happy"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 1
        assert fixture.stories[0].as_a == "someone"
        assert fixture.stories[0].i_want_to == "do something"
        assert fixture.stories[0].so_that == "I'm happy"
Beispiel #9
0
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    class DoSomethingAction(ActionBase):
        regex = r'I do something$'

        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction(ActionBase):
        regex = r'I do something else$'

        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction(ActionBase):
        regex = r'I do yet another thing$'

        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    settings.tests_dirs = [abspath(dirname(__file__))]
    settings.file_pattern = "some_test.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert_no_invalid_stories(fixture)

    assert len(
        fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
    assert len(fixture.stories[0].scenarios) == 2
    assert "#some custom comment" in fixture.stories[0].scenarios[1].whens[
        0].description
Beispiel #10
0
def test_parsing_folder_with_no_stories_returns_empty_list():
    settings = Settings()
    settings.tests_dirs = [
        abspath(join(dirname(__file__), "no_stories_folder"))
    ]
    parser = FileParser()

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 0
def test_parsing_stories_returns_list():
    settings = Settings()
    filemock = Mock()
    filemock.expects(once()) \
            .list_files(directories=same(settings.tests_dirs), pattern=same(settings.file_pattern)) \
            .will(return_value([]))
    parser = FileParser(file_object=filemock)

    fixture = parser.get_stories(settings=settings)
    assert isinstance(fixture, Fixture)
def test_is_not_keyword():
    language_mock = Mock()
    language_mock.expects(once()) \
                 .get(eq("keyword")) \
                 .will(return_value("kw"))

    parser = FileParser(language=language_mock, file_object=None)
    is_keyword = parser.is_keyword("other", "keyword")

    assert not is_keyword
    language_mock.verify()
def test_is_not_scenario_starter_line():
    language_mock = Mock()
    language_mock.expects(once()) \
                 .get(eq("scenario")) \
                 .will(return_value("Scenario"))

    parser = FileParser(language=language_mock, file_object=None)
    is_scenario_starter_line = parser.is_scenario_starter_line("Cenario bla")
    
    assert not is_scenario_starter_line
    language_mock.verify()
Beispiel #14
0
def test_parsing_files_with_wrong_so_that_returns_no_story_header_list():
    settings = Settings()
    settings.tests_dirs = [abspath(join(dirname(__file__), "invalid_content_stories"))]
    settings.file_pattern = "invalid_so_that.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert len(fixture.no_story_header) == 1
    file_path = fixture.no_story_header[0]
    assert file_path.endswith("invalid_so_that.acc")
def test_parsing_folder_with_no_stories_returns_empty_list():
    settings = Settings()
    files = []
    filemock = Mock()
    filemock.expects(once()) \
            .list_files(directories=same(settings.tests_dirs), pattern=same(settings.file_pattern)) \
            .will(return_value(files))

    parser = FileParser(file_object=filemock)

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 0
    filemock.verify()
Beispiel #16
0
def test_is_not_keyword():
    
    mocker = Mocker()
    
    language_mock = mocker.mock()
    language_mock.get("keyword")
    mocker.result("kw")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        is_keyword = parser.is_keyword("other", "keyword")
    
        assert not is_keyword
Beispiel #17
0
def test_is_not_keyword():

    mocker = Mocker()

    language_mock = mocker.mock()
    language_mock.get("keyword")
    mocker.result("kw")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        is_keyword = parser.is_keyword("other", "keyword")

        assert not is_keyword
Beispiel #18
0
def test_is_not_scenario_starter_line():
    
    mocker = Mocker()
    
    language_mock = mocker.mock()
    language_mock.get("scenario")
    mocker.result("Scenario")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        is_scenario_starter_line = parser.is_scenario_starter_line("Cenario bla")
        
        assert not is_scenario_starter_line
Beispiel #19
0
def test_parsing_files_with_wrong_i_want_to_returns_no_story_header_list():
    settings = Settings()
    settings.tests_dirs = [
        abspath(join(dirname(__file__), "invalid_content_stories"))
    ]
    settings.file_pattern = "invalid_i_want_to.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert len(fixture.no_story_header) == 1
    file_path = fixture.no_story_header[0]
    assert file_path.endswith("invalid_i_want_to.acc")
Beispiel #20
0
def test_is_not_scenario_starter_line():

    mocker = Mocker()

    language_mock = mocker.mock()
    language_mock.get("scenario")
    mocker.result("Scenario")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        is_scenario_starter_line = parser.is_scenario_starter_line(
            "Cenario bla")

        assert not is_scenario_starter_line
Beispiel #21
0
def test_parsing_stories_returns_list():
    
    mocker = Mocker()
    
    settings = Settings()
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
    mocker.result([])
    
    with mocker:
        parser = FileParser(file_object=filemock)
    
        fixture = parser.get_stories(settings=settings)
        assert isinstance(fixture, Fixture)
Beispiel #22
0
def test_parsing_stories_returns_list():

    mocker = Mocker()

    settings = Settings()
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result([])

    with mocker:
        parser = FileParser(file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert isinstance(fixture, Fixture)
Beispiel #23
0
def test_parsing_folder_with_no_stories_returns_empty_list():
    
    mocker = Mocker()
    
    settings = Settings()
    files = []
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
    mocker.result(files)

    with mocker:
        parser = FileParser(file_object=filemock)
    
        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 0
Beispiel #24
0
def test_parsing_folder_with_no_stories_returns_empty_list():

    mocker = Mocker()

    settings = Settings()
    files = []
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)

    with mocker:
        parser = FileParser(file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 0
Beispiel #25
0
def test_can_create_file_parser_with_mocked_filesystem():

    mocker = Mocker()

    filemock = mocker.mock()
    parser = FileParser(file_object=filemock)

    assert parser.file_object == filemock
def test_parse_scenario_line():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="some file")

    settings_mock = Mock()
    settings_mock.scenarios_to_run = []

    language_mock = Mock()
    language_mock.expects(once()) \
                 .get(eq("scenario")) \
                 .will(return_value("Scenario")) \

    parser = FileParser(language=language_mock, file_object=None)
    scenario = parser.parse_scenario_line(story, "Scenario 1 - Doing something", settings_mock)

    assert scenario is not None
    assert scenario.index == "1", "Expected 1 actual %s" % scenario.index
    assert scenario.title == "Doing something"

    language_mock.verify()
Beispiel #27
0
def test_parse_scenario_line():
    
    mocker = Mocker()
    
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="some file")

    settings_mock = mocker.mock()
    settings_mock.scenarios_to_run
    mocker.result([])
    
    language_mock = mocker.mock()
    language_mock.get("scenario")
    mocker.result("Scenario")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        scenario = parser.parse_scenario_line(story, "Scenario 1 - Doing something", settings_mock)
    
        assert scenario is not None
        assert scenario.index == "1", "Expected 1 actual %s" % scenario.index
        assert scenario.title == "Doing something"
def test_parsing_files_with_invalid_so_that_returns_invalid_files_list():
    settings = Settings()
    files = ["some path"]
    
    story_text = """As a someone
I want to do something
So I'm happy"""

    filemock = Mock()
    filemock.expects(once()) \
            .list_files(directories=same(settings.tests_dirs), pattern=same(settings.file_pattern)) \
            .will(return_value(files))
    filemock.expects(once()) \
            .read_file(eq(files[0])) \
            .will(return_value(story_text))

    language_mock = Mock()
    language_mock.expects(once()) \
                 .get(eq("as_a")) \
                 .will(return_value("As a"))
    language_mock.expects(once()) \
                 .get(eq("i_want_to")) \
                 .will(return_value("I want to"))
    language_mock.expects(once()) \
                 .get(eq("so_that")) \
                 .will(return_value("So that"))
    language_mock.expects(once()) \
                 .get(eq("no_header_failure")) \
                 .will(return_value("No header found"))

    parser = FileParser(language=language_mock, file_object=filemock)

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.no_story_header) == 1
    file_path = fixture.no_story_header[0]
    assert file_path == "some path"
    language_mock.verify()
    filemock.verify()
Beispiel #29
0
def test_parse_block_lines():
    parser = FileParser(None, None, None)
    
    line_index = 5
    line = "And I see table as:"
    scenario_lines = [
        'Line 1',
        'Line 2',
        'Line 3',
        'Scenario bla',
        'Given',
        '    And I see table as:',
        '        | Name | Age | Sex  |',
        '        | Paul | 28  | Male |',
        '        | John | 30  | Male |'
    ]
    offset, rows, parsed_rows = parser.parse_rows(line_index, line, scenario_lines)
    
    assert offset == 3
    assert rows == [
        '        | Name | Age | Sex  |',
        '        | Paul | 28  | Male |',
        '        | John | 30  | Male |'
    ]
    assert parsed_rows == [
                        {
                            'Name':'Paul',
                            'Age':'28',
                            'Sex':'Male'
                        },
                        {
                            'Name':'John',
                            'Age':'30',
                            'Sex':'Male'
                        }
                   ]
def test_parsing_files_with_proper_header_returns_parsed_scenario():
    settings = Settings()
    files = ["some path"]
    
    story_text = """As a someone
I want to do something
So that I'm happy"""

    filemock = Mock()
    filemock.expects(once()) \
            .list_files(directories=same(settings.tests_dirs), pattern=same(settings.file_pattern)) \
            .will(return_value(files))
    filemock.expects(once()) \
            .read_file(eq(files[0])) \
            .will(return_value(story_text))

    language_mock = Mock()
    language_mock.expects(once()) \
                 .get(eq("as_a")) \
                 .will(return_value("As a"))
    language_mock.expects(once()) \
                 .get(eq("i_want_to")) \
                 .will(return_value("I want to"))
    language_mock.expects(once()) \
                 .get(eq("so_that")) \
                 .will(return_value("So that"))

    parser = FileParser(language=language_mock, file_object=filemock)

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 1
    assert fixture.stories[0].as_a == "someone"
    assert fixture.stories[0].i_want_to == "do something"
    assert fixture.stories[0].so_that == "I'm happy"
    language_mock.verify()
    filemock.verify()
Beispiel #31
0
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    
    mocker = Mocker()
    
    class DoSomethingAction:
        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction:
        def execute(context, *args, **kwargs):
            pass
    class DoYetAnotherThingAction:
        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    files = ["some path"]
    
    story_text = """As a someone
I want to do something
So that I'm happy

Scenario 1 - Test Scenario
Given
    I do something
When
    I do something else
Then
    I do yet another thing

Scenario 2 - Test Scenario
Given
    I do something
When
    #some custom comment
Then
    I do yet another thing"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs, pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("given")
    mocker.result("Given")
    mocker.count(min=1, max=None)
    language_mock.get("when")
    mocker.result("When")
    mocker.count(min=1, max=None)
    language_mock.get("then")
    mocker.result("Then")
    mocker.count(min=1, max=None)
    language_mock.get("scenario")
    mocker.result("Scenario")
    mocker.count(min=1, max=None)

    action_registry_mock = mocker.mock()
    action_registry_mock.suitable_for("I do something", 'en-us')
    mocker.result((DoSomethingAction, [], {}))
    mocker.count(min=1, max=None)
    action_registry_mock.suitable_for("I do something else", 'en-us')
    mocker.result((DoSomethingElseAction, [], {}))
    mocker.count(min=1, max=None)
    action_registry_mock.suitable_for("I do yet another thing", 'en-us')
    mocker.result((DoYetAnotherThingAction, [], {}))
    mocker.count(min=1, max=None)

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock, action_registry=action_registry_mock)
    
        fixture = parser.get_stories(settings=settings)
    
        assert_no_invalid_stories(fixture)
    
        assert len(fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
        assert len(fixture.stories[0].scenarios) == 2
        assert "#some custom comment" in fixture.stories[0].scenarios[1].whens[0].description, "Expected \"#some custom comment\", Actual: \"%s\"" % fixture.stories[0].scenarios[1].whens[0].description
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    class DoSomethingAction:
        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction:
        def execute(context, *args, **kwargs):
            pass
    class DoYetAnotherThingAction:
        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    files = ["some path"]
    
    story_text = """As a someone
I want to do something
So that I'm happy

Scenario 1 - Test Scenario
Given
    I do something
When
    I do something else
Then
    I do yet another thing

Scenario 2 - Test Scenario
Given
    I do something
When
    #some custom comment
Then
    I do yet another thing"""

    filemock = Mock()
    filemock.expects(once()) \
            .list_files(directories=same(settings.tests_dirs), pattern=same(settings.file_pattern)) \
            .will(return_value(files))
    filemock.expects(once()) \
            .read_file(eq(files[0])) \
            .will(return_value(story_text))

    language_mock = Mock()
    language_mock.expects(at_least_once()) \
                 .get(eq("as_a")) \
                 .will(return_value("As a"))
    language_mock.expects(at_least_once()) \
                 .get(eq("i_want_to")) \
                 .will(return_value("I want to"))
    language_mock.expects(at_least_once()) \
                 .get(eq("so_that")) \
                 .will(return_value("So that"))
    language_mock.expects(at_least_once()) \
                 .get(eq("given")) \
                 .will(return_value("Given"))
    language_mock.expects(at_least_once()) \
                 .get(eq("when")) \
                 .will(return_value("When"))
    language_mock.expects(at_least_once()) \
                 .get(eq("then")) \
                 .will(return_value("Then"))
    language_mock.expects(at_least_once()) \
                 .get(eq("scenario")) \
                 .will(return_value("Scenario"))

    action_registry_mock = Mock()
    action_registry_mock.expects(at_least_once()) \
                        .suitable_for(eq("I do something"), eq('en-us')) \
                        .will(return_value((DoSomethingAction, [], {})))
    action_registry_mock.expects(at_least_once()) \
                        .suitable_for(eq("I do something else"), eq('en-us')) \
                        .will(return_value((DoSomethingElseAction, [], {})))
    action_registry_mock.expects(at_least_once()) \
                        .suitable_for(eq("I do yet another thing"), eq('en-us')) \
                        .will(return_value((DoYetAnotherThingAction, [], {})))

    parser = FileParser(language=language_mock, file_object=filemock, action_registry=action_registry_mock)

    fixture = parser.get_stories(settings=settings)

    assert_no_invalid_stories(fixture)

    assert len(fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
    assert len(fixture.stories[0].scenarios) == 2
    assert fixture.stories[0].scenarios[1].whens[0].description == "#some custom comment"

    language_mock.verify()
    filemock.verify()
    action_registry_mock.verify()
Beispiel #33
0
 def __init__(self, parser=None, runner=None, hooks=None):
     self.parser = parser or FileParser()
     self.runner = runner
     sys.path.insert(0, os.getcwd())
     self.used_elements = {}
     self.hooks = hooks and hooks or Hooks
Beispiel #34
0
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():

    mocker = Mocker()

    class DoSomethingAction:
        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction:
        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction:
        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    files = ["some path"]

    story_text = """As a someone
I want to do something
So that I'm happy

Scenario 1 - Test Scenario
Given
    I do something
When
    I do something else
Then
    I do yet another thing

Scenario 2 - Test Scenario
Given
    I do something
When
    #some custom comment
Then
    I do yet another thing"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("given")
    mocker.result("Given")
    mocker.count(min=1, max=None)
    language_mock.get("when")
    mocker.result("When")
    mocker.count(min=1, max=None)
    language_mock.get("then")
    mocker.result("Then")
    mocker.count(min=1, max=None)
    language_mock.get("scenario")
    mocker.result("Scenario")
    mocker.count(min=1, max=None)

    action_registry_mock = mocker.mock()
    action_registry_mock.suitable_for("I do something", 'en-us')
    mocker.result((DoSomethingAction, [], {}))
    mocker.count(min=1, max=None)
    action_registry_mock.suitable_for("I do something else", 'en-us')
    mocker.result((DoSomethingElseAction, [], {}))
    mocker.count(min=1, max=None)
    action_registry_mock.suitable_for("I do yet another thing", 'en-us')
    mocker.result((DoYetAnotherThingAction, [], {}))
    mocker.count(min=1, max=None)

    with mocker:
        parser = FileParser(language=language_mock,
                            file_object=filemock,
                            action_registry=action_registry_mock)

        fixture = parser.get_stories(settings=settings)

        assert_no_invalid_stories(fixture)

        assert len(fixture.stories) == 1, "Expected 1, Actual: %d" % len(
            fixture.stories)
        assert len(fixture.stories[0].scenarios) == 2
        assert fixture.stories[0].scenarios[1].whens[
            0].description == "#some custom comment"
Beispiel #35
0
def test_can_create_file_parser():
    parser = FileParser()

    assert isinstance(
        parser, FileParser
    ), "The created instance should be an instance of FileParser but was %s" % parser.__class__