Exemple #1
0
    def test_formatter_background_called_when_feature_has_background(self):
        feature = model.Feature('foo.feature', 1, u'Feature', u'foo',
                                background=Mock())

        feature.run(self.runner)

        self.formatter.background.assert_called_with(feature.background)
Exemple #2
0
    def test_formatter_background_not_called_when_feature_has_no_background(
            self):
        feature = model.Feature('foo.feature', 1, u'Feature', u'foo')

        feature.run(self.runner)

        assert not self.formatter.background.called
Exemple #3
0
    def test_formatter_feature_called(self):
        feature = model.Feature('foo.feature', 1, u'Feature', u'foo',
                                background=Mock())

        feature.run(self.runner)

        self.formatters[0].feature.assert_called_with(feature)
Exemple #4
0
    def test_run_runs_named_scenarios(self):
        scenarios = [Mock(model.Scenario), Mock(model.Scenario)]
        scenarios[0].name = 'first scenario'
        scenarios[1].name = 'second scenario'
        scenarios[0].tags = []
        scenarios[1].tags = []
        # -- FAKE-CHECK:
        scenarios[0].should_run_with_name_select.return_value = True
        scenarios[1].should_run_with_name_select.return_value = False

        for scenario in scenarios:
            scenario.run.return_value = False

        self.config.tags.check.return_value = True
        self.config.name = ['first', 'third']
        self.config.name_re = Configuration.build_name_re(self.config.name)

        feature = model.Feature('foo.feature',
                                1,
                                u'Feature',
                                u'foo',
                                scenarios=scenarios)

        feature.run(self.runner)

        scenarios[0].run.assert_called_with(self.runner)
        assert not scenarios[1].run.called
        scenarios[0].should_run_with_name_select.assert_called_with(
            self.config)
        scenarios[1].should_run_with_name_select.assert_called_with(
            self.config)
Exemple #5
0
 def _build_feature(self, keyword, line):
     name = line[len(keyword) + 1:].strip()
     language = self.language or DEFAULT_LANGUAGE
     self.feature = model.Feature(self.filename, self.line, keyword,
                                  name, tags=self.tags, language=language)
     # -- RESET STATE:
     self.tags = []
Exemple #6
0
    def test_feature_hooks_not_run_if_feature_not_being_run(self):
        self.config.tags.check.return_value = False

        feature = model.Feature('foo.feature', 1, u'Feature', u'foo')

        feature.run(self.runner)

        assert not self.run_hook.called
Exemple #7
0
 def _build_feature(self, keyword, line):
     name = line[len(keyword) + 1:].strip()
     self.feature = model.Feature(self.filename,
                                  self.line,
                                  keyword,
                                  name,
                                  tags=self.tags)
     # -- RESET STATE:
     self.tags = []
Exemple #8
0
 def _build_feature(self, keyword, line):
     name = line[len(keyword) + 1:].strip()
     language = self.language or DEFAULT_LANGUAGE
     feature = model.Feature(self.filename, self.line, keyword, name,
                             tags=self.tags, language=language)
     self.feature = feature
     self.scenario_container = feature
     self.rule = None
     # -- RESET STATE:
     self.tags = []
Exemple #9
0
    def parse_feature(self, json_feature):
        name = json_feature.get("name", u"")
        keyword = json_feature.get("keyword", None)
        tags = json_feature.get("tags", [])
        description = json_feature.get("description", [])
        location = json_feature.get("location", u"")
        filename, line = location.split(":")
        feature = model.Feature(filename, line, keyword, name, tags, description)

        json_elements = json_feature.get("elements", [])
        for json_element in json_elements:
            self.add_feature_element(feature, json_element)
        return feature
Exemple #10
0
    def test_run_runs_scenarios(self):
        scenarios = [Mock(), Mock()]
        for scenario in scenarios:
            scenario.run.return_value = False

        self.config.tags.check.return_value = True

        feature = model.Feature('foo.feature', 1, u'Feature', u'foo',
                                scenarios=scenarios)

        feature.run(self.runner)

        for scenario in scenarios:
            scenario.run.assert_called_with(self.runner)
Exemple #11
0
    def action_init(self, line):
        line = line.strip()

        if line.startswith('@'):
            self.tags.extend([model.Tag(tag.strip(), self.line)
                for tag in line[1:].split('@')])
            return True
        feature_kwd = self.match_keyword('feature', line)
        if feature_kwd:
            name = line[len(feature_kwd) + 1:].strip()
            self.feature = model.Feature(self.filename, self.line, feature_kwd,
                                         name, tags=self.tags)
            self.tags = []
            self.state = 'feature'
            return True
        return False
Exemple #12
0
    def test_run_runs_named_scenarios_with_regexp(self):
        scenarios = [Mock(), Mock()]
        scenarios[0].name = 'first scenario'
        scenarios[1].name = 'second scenario'
        scenarios[0].tags = []
        scenarios[1].tags = []

        for scenario in scenarios:
            scenario.run.return_value = False

        self.config.tags.check.return_value = True
        self.config.name = ['third .*', 'second .*']
        self.config.name_re = Configuration.build_name_re(self.config.name)

        feature = model.Feature('foo.feature', 1, u'Feature', u'foo',
                                scenarios=scenarios)

        feature.run(self.runner)

        assert not scenarios[0].run.called
        scenarios[1].run.assert_called_with(self.runner)