All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.iskrenyp.slackreporter.api.SlackReporterAnnotationDrivenExtension.groovy Maven / Gradle / Ivy

Go to download

A simple annotation driven local extension for Spock framework, which enables you to screen record your Specifications

There is a newer version: 1.0.4
Show newest version
package com.github.iskrenyp.slackreporter.api

import com.github.iskrenyp.slackreporter.SlackReporterConfigEntity
import com.github.iskrenyp.slackreporter.service.SlackReportingServiceImpl
import com.github.iskrenyp.slackreporter.slack.SlackSimpleClient
import org.spockframework.runtime.AbstractRunListener
import org.spockframework.runtime.extension.AbstractAnnotationDrivenExtension
import org.spockframework.runtime.model.ErrorInfo
import org.spockframework.runtime.model.SpecInfo

class SlackReporterAnnotationDrivenExtension extends AbstractAnnotationDrivenExtension {

    SlackReportingServiceImpl service
    SlackReporterConfigEntity configEntity

    List failedMethods = []
    Integer failsCount = 0

    @Override
    void visitSpecAnnotation(ReportOnSlack annotation, SpecInfo spec) {
        spec.addListener(new AbstractRunListener() {

            @Override
            void afterSpec(SpecInfo specInfo) {
                configEntity = service.prepareNotification(annotation.value(), failsCount, failedMethods)
                if (configEntity) service.sendNotification(configEntity)
            }

            @Override
            void beforeSpec(SpecInfo specInfo) {
                service = new SlackReportingServiceImpl(annotation.value(), new SlackSimpleClient())
            }

            @Override
            void error(ErrorInfo error) {
                failsCount++
                failedMethods << error.method.feature.name
            }
        })
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy