test ``` class WeatherPresenterTest : Spek ({ giv...
# spek
r
test
Copy code
class WeatherPresenterTest : Spek ({
	given("a weather presenter") {
		val repository 	= mock<WeatherRepository>()
		val view		= mock<WeatherView>()

		val presenter 	= WeatherPresenter(repository)

		beforeEachTest {
			presenter.attachView(view)
		}

		whenever("fetch weather") {
			then("return success") {
				repository.fetchWeather() willReturnSingle weatherData // this weatherData from fixture
				
				presenter.fetchWeather()

				verify(view).onLoadWeatherSuccess(weatherData)
				verifyNoMoreInteraction(view)
			}

			then("return error") {
				repository.fetchWeather() willReturnSingleError weatherDataError // this weatherData from fixture
				
				presenter.fetchWeather()

				verify(view).onLoadWeatherError(weatherDataError)
				verifyNoMoreInteraction(view)
			}
		}

		afterEachTest {
			presenter.detachView()
		}
	}
})